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.
This algo works ! And it's indeed O(n) .
- shyJohnnie August 09, 2013Say we have two Arrays:
A=[ 0 1 0 0 0 1 0 0 1 0 0]
B=[ 1 0 1 1 1 0 1 1 0 1 0]
Then we create two arrays : C[i] = A[i] - B[i] . D[i] = D[i-1] + C[i];
C=[-1 1 -1 -1 -1 1 -1 -1 1 -1 0]
D=[-1,0,-1,-2,-3,-2,-3,-4,-3,-4,-4]
now we consider D-array. if D[i] == D[j] , what does it means ?
it means sum( C[i,j ] ) ==0 .
and since C[i] =A[i] - B[i] , now it means sum( A[i,j] ) == sum ( B[i, j] )
so now the task becomes find two indices in D[] ,and (j - i) is maximum.
we need the help of HashMap.
Here is the algo:
1.create D[] Array. init a empty hash_map
2.traverse the D[] Array , if D[j] exists in hash_map (let's say its valus is i ),then we update the answer with (i, j ) ;
3. if D[j] doesn't exist in hash_map , insert it !
4.finally ,we got the answer , and now you see we only traverse the D[] array one time , so the complexity is O(n ).
5. thanks!