Google Interview Question for Java Developers

Country: United States

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

If each location have index of x and y then if each white chess x is between at least two black chesses x with same y and each white chess y is between at least two black chess with same x then that chess is surrounded by black chesses.
1. Sort all black chesses by x in array A in O(n lg n) time.
2. Sort all black chesses by y in array B in O(n lg n) time.
3. For each white chess search for its x in the first array in O(lg n). Compare y of this white chess with y of all matched y chesses ( in worst case it takes O(n) ). If it is between at least two of them then do the same process for x. If either of these cases does not match then ignore this chess. Otherwise continue to the next chess.
If there are n black chess and m white chess then the worse case running time of the algorithm is O( n lg n + n m ).

- nooreddin February 14, 2018 | Flag Reply

Add a Comment

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


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

Learn More


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.

Learn More

Resume Review

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.

Learn More

Mock Interviews

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.

Learn More