is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
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.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
O(log n) solution:
- menglingquan88723 July 16, 2015class Program
{
private static int targetIndex = 9;
static void Main(string[] args)
{
// Time complexity is O(log n)
int sum = 0;
int[] test = {1,2,3,4,5,6,7,8,9,10};
for (int i = 0; i < test.Length - 1; i++ )
{
var temp = 0;
GetTargetIndexForEachElement(test, i, 0, targetIndex, 7);
if(targetIndex <= i)
{
temp = test.Length - i - 1;
}
else
{
temp = test.Length - targetIndex;
}
sum += temp;
}
Console.WriteLine(sum);
}
private static void GetTargetIndexForEachElement(int[] array, int current, int start, int end, int limit)
{
// Brute force.
if(start+1 >= end)
{
for(int i=start; i<=end; i++)
{
if(array[current] + array[i] > limit)
{
targetIndex = i;
break;
}
}
}
else
{
int midIndex = (start + end)/2;
// Recursion modify value of a private static integer to make it work.
if (array[current] + array[midIndex] < limit)
GetTargetIndexForEachElement(array, current, midIndex, end, limit);
else if (array[current] + array[midIndex] > limit)
GetTargetIndexForEachElement(array, current, start, midIndex, limit);
else
{
targetIndex = midIndex + 1;
}
}
}
}