Google Interview Question for Software Engineer / Developers


Country: India




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

Let's assume
1. The distance between two poles is 1 unit.
2. The tallest pole is 10unit height.
3. The shortest one is 1 unit, clear from the problem.

Now,
If two tallest pole are neighbor (10 10), then you need only 1 unit of wire to connect.
But if one pole is 10 and another pole is 1, now you need a diagonal distance (sqrt(10*10+1))

Happy case: All the pole is same height
Worst case: One pole is max height, 10 and the next one is 1. It will look like a triangular wave.

Just need to sum up all the non horizontal(diagonal) line of the wave.

- Md Omar Faroque August 24, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
3
of 3 votes

if one pole is 10 and another pole is 1, now you need a diagonal distance (sqrt(9*9+1)) because you need to substract shorter height from longer to calculate the diagonal length.

- Anuj August 26, 2022 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can apply pythagoras theoram to solve the problem.

- Devang barot August 29, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1: lets assume that the distance between each pole is the same or contant.
2: lets assume that the minimum length of the wire required to join the two poles is the constant distance of the pole between each other.
3: less compare the two poles if the height are the same then we know that we need just the constant distance of the pole as the required length of wire to connect the poles. If the height of the two poles are not the same then we substract the poles among them between the highest and the small pole after substracting, we add the constant distance between two poles and the substracted value, so thats going to be our required wire length to join the two not poles with wire.
Thinking this approach will work.

- usmanfaki September 19, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is exactly what I think too,

For e.g let's say the maximum pole height is 10 units and the constant distance between two poles is 5 units, therefore the length of wire to connect two poles of the same height is 5 units, but the length of wire required to connect the pole A(10 units) and pole B(6 units) is 5 + (10 - 6) which will give 9 units length of wire required to connect the two poles A and B.

Therefore the solution is to get the length of wire between the current pole and the next pole by finding their height difference and adding it to the constant distance between the two poles and then adding the length to the total length of wire required.

- Peter Akwa November 08, 2022 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here as the question mentions the height of all these poles are constantly changing and hence they can vary for anything between 1-> maxheight, So hence what I think is it is just a max(max_hi[i]-1, max_hi[i+1]-1) and this would be the required length to connect 2 poles no matter what the situation is.

- Anonymous January 03, 2024 | 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