TP Interview Question for Software Engineer / Developers






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

Homework? What is TP? Full form?

- Anonymous August 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hint: It is possible in O(log n) by maintaining two (balanced) trees, one for the sign of x and the other for the sign of xy.

- Anonymous August 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

interviewstreet.com

- Anonymous August 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am not sure I understand. Just to read all points will take O(N). If we want to refelct all points between the minimal and maximal, it will take O(N) just to put "-" or '+' in front of all them.

- Nemo September 01, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The question is about a datastructure i suppose.

Once you are given the n points (assume you preprocess them somehow), you need to repeatedly be able to do 1,2,3. IN which case with O(nlogn) preprocessing, O(logn) for 1,2,3 is possible.

- Anonymous September 02, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I guess, it won't serve the purpose.

I tried using maintaining cumulative total of the count for each quadrant at each position so that I can return the number of points in that particular quadrant in O(1) using cnt(j)-cnt(j-1)

But dunno how to go about reflection :(

- Anonymous September 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is possible. Think harder. The second post has it.

- Anonymous September 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Preprocessing (while reading the points)
(1) Construct a balanced binary search tree which keeps the points as it's value. i.e first compare with x coordinates, if they are equal then compare with the y coordinates. At each node also keep the count of points in each quadrant at that time including that point.

Running the query :
(1) Find the point (xi, yi) -> O(logn) . q1, q2, q3, q4.
(2) Find the point (xj, yj) -> O(logn) . q'1, q'2, q'3, q'4.
(3) Ans = ((q'1 - q1), (q'2 - q2), (q'3 - q3), (q'4 - q4)); -> O(1)
(4) Find the quadrant of point (xi, yi). Add one to that entry of the answer. i.e if quadrant is 1 then Ans += (1,0,0,0) -> O(1)

Hence in O(logn)

- Anonymous September 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Preprocessing (while reading the points)
(1) Construct a balanced binary search tree which keeps the points as it's value. i.e first compare with x coordinates, if they are equal then compare with the y coordinates. At each node also keep the count of points (after applying the queries between 0, i.) in each quadrant at that time including that point.

Running the query :
(1) Find the point (xi, yi) -> O(logn) . q1, q2, q3, q4.
(2) Find the point (xj, yj) -> O(logn) . q'1, q'2, q'3, q'4.
(3) Ans = ((q'1 - q1), (q'2 - q2), (q'3 - q3), (q'4 - q4)); -> O(1)
(4) Find the quadrant of point (xi, yi). Add one to that entry of the answer. i.e if quadrant is 1 then Ans += (1,0,0,0) -> O(1)

Hence in O(logn)

- Anonymous September 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I want to give you all hint about one data structure which is allready available

that is "segment tree with lazy propagation" this is the ultimate way to solve that problem

reason

we want to avoid two things to optimize code
avoid flipping of bits . flip bits when actually needed
avoid re-computation of results(counting no of points in quadrants)

- Tushar October 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

woolor.com/InterviewMitra/47/amazon-quadrant-queries

- InterviewMitra October 21, 2012 | Flag Reply


Add a Comment
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.

Learn More

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.

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