## N/A Interview Question for Software Engineer / Developers

Country: United States

Comment hidden because of low score. Click to expand.
1
of 1 vote

Can you explain the question a bit more?

highestInterval( 50 ):
What is the interval between? What is the base/starting value?

Assuming starting val is 100(minimum of all entries):
So we'relooking for val between 100-150:
Answer should be: 110, its count is 10

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````static void Main(string[] args)
{
var inputs = new[] {
new [] {100, 2 },
new [] {100, 1 },
new [] {110, 10 },
new [] {200, 4 },
new [] {1000, 3 },
new [] {1200, 8 }
};

int range = 50;
int value = HighestInterval(inputs, range);
}

private static int HighestInterval(int[][] inputs, int range)
{
int start = 0;
int end = 0;
int total = 0;
int maxIndex = 0;
int maxTotal = 0;
int size = inputs.GetLength(0);

do
{
while (inputs[end][0] - inputs[start][0]  > range){
total-=inputs[start][1];
start++;
}

total += inputs[end][1];

if (maxTotal < total){
maxIndex = start;
maxTotal = total;
}

end++;
}while (end < size);

return inputs[maxIndex][0];
}
}``````

Comment hidden because of low score. Click to expand.
0

ahh, thank you. I should've thought about using a head and a tail.

Comment hidden because of low score. Click to expand.
0

I assume you mean +- instead of -= on that one line.
This looks like it fails on certain inputs, like:
100, 1
110, 5
119, 1
121, 6

If range = 20, won't this return 119 instead of 110?

I think you really need to try every possible start position, but that makes it O(n^2) on certain inputs...

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.