Jay
BAN USER// C# version without dictionary
public static void FindFirstNotRepeated()
{
var arr = new int[] { 5, 7, 8, 9, 2, 3, 5, 2, 7, 0 };
var distinct = new List<int>();
for (int i = 0; i < arr.Length; i++)
{
if (distinct.Contains(arr[i]))
{
distinct.Remove(arr[i]);
}
else
{
distinct.Add(arr[i]);
}
}
if (distinct.Count > 0)
{
Console.WriteLine("First Non Repeating: " + distinct[0]);
}
else
{
Console.WriteLine("No Non Repeating Numbers.");
}
}
// Here's my solution in C#. Runtime complexity will be O(n).
public static void FindMaxGates()
{
// Convert time to seconds
int[] arr = { 570, 675, 990 };
int[] dept = { 705, 690, 1005 };
// You need atleast one gate
int gateCount = 1;
// If Next arrival is less than previous departure, Add gate
for (int i = 0; i < arr.Length; i++)
{
if (i + 1 >= arr.Length)
{
break;
}
if (arr[i + 1] < dept[i])
{
gateCount++;
}
}
Console.WriteLine("Gates Needed: {0}", gateCount);
}
Here are some of the questions you can ask that would take the discussion further:
- Jay February 18, 20171. What metrics are tracking today?
2. What are the problems with it?
3. Is this a system limitation (here you can talk about problems of scale) or do we need to track more relevant metrics
4. What are the goals - do we want to improve user experience, drive more sales or more of an system optimization such as better inventory management.
The interviewer will then likely lead the discussion where they intended to. This could be very technical (gauging your depth) or they may just be gauging if you are thinking of the problem broadly enough.