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.
No, I think in the problem, we are given a stream of insertions and deletions instead of given x directly (x only exists in logic)
- zhenli3 December 02, 2011e.g. steam = {insert 5, insert 10, delete 5, insert 3, delete 3, ...}
let's denote the stream as S. For simplicity, we can assume that all the elements are positive integers.
So, S={+5, +10, -5, +3, -3, ...}.
1) To decide if |A|=0
simply count
P = #total insertion - #total deletion = \Sigma_{i from 1 to |S|} sign(S[i])
if P=0, then |A|=0
if P>0, then |A|>0
(P<0 couldn't happen)
In other words, |A|=0 iff P=0
2) To decide if |A|=1
First count P as in 1).
If P=0, we know A=0; otherwise, count
Q = \Sigma_{i from 1 to |S|} S[i]
Then check for Q/P,
if x[Q/P] = #(insertion of Q/P) - #(deletion Q/P) = P holds
if yes, then |A|=1
otherwise, |A|>1
=================
Examples:
S={1,2,3,-3,-1,-2} => P=0 => |A|=0
S={1,2,3,-3} => P=2, Q=3 => x[3/2] != P => |A|>1
S={1,2,3,-1,-2,3} => P=2, Q=6 => x[6/2] == P => |A|=1
=================
Both algorithms runs in O(N) time (N is the length of the stream), and memory cost is only O(1)