Order of People Heights Problem Statement

Consider 'N' individuals numbered from 0 to N-1 standing in a queue. You are provided with two arrays: Height and Infront, each consisting of 'N' non-negative integers. Height[i] indicates the height of the ith person, and Infront[i] indicates the number of individuals who are taller than the ith person and stand in front of them in the queue.

Your task is to determine the actual order of people in the queue. The result should be an array of 'N' integers where the ith integer represents the height of the person positioned at the ith place from the front of the queue.

Example:

Input:
N = 6
Height = [5, 3, 2, 6, 1, 4]
Infront = [0, 1, 2, 0, 3, 2]
Output:
[5, 3, 2, 1, 6, 4]
Explanation:

In the resulting order, the specified conditions for the number of taller individuals in front are satisfied for each person.

Constraints:

  • 1 <= T <= 50
  • 1 <= N <= 10^4
  • 1 <= Height[i] <= 10^9
  • 0 <= Infront[i] < N
Note:
The elements in the 'Height' array are unique, ensuring a valid order always exists given the 'Height' and 'Infront' arrays. Implement the function without printing anything.
AnswerBot
1y

The task is to find the actual order of people in a queue based on their heights and the number of taller people in front of them.

  • Iterate through the given arrays and create a list of tuples containin...read more

Help your peers!
Add answer anonymously...
Nvidia Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter