Rebuild the Line From Taller-in-Front Counts
Updated
Problem statement
There are n people, numbered from 0 to n - 1, who were standing in one line, one behind another. All of them have different heights. You are given two integer arrays: heights[i] is the height of person i, and tallerInFront[i] is how many of the people standing in front of person i were taller than person i.
Rebuild the line. Return the heights of the people in line order, from the front of the line to the back.
The input always matches exactly one line.
Function
orderOfPeople(heights: int[], tallerInFront: int[]) → int[]Examples
Example 1
heights = [5,3,8,6]tallerInFront = [0,2,0,1]return = [5,8,3,6]Check the line [5, 8, 3, 6] from the front. Nobody stands in front of 5, so its count is 0. Only 5 stands in front of 8, and it is shorter, so the count is 0. Both 5 and 8 stand in front of 3 and are taller, so the count is 2. Of 5, 8 and 3 in front of 6, only 8 is taller, so the count is 1.
These are exactly the given counts for heights 5, 3, 8 and 6.
Example 2
heights = [4,9,2,7]tallerInFront = [2,0,3,1]return = [9,7,4,2]The person of height 2 has all 3 other people in front, and all of them are taller, so 2 is last. In the line [9, 7, 4, 2], each person has every taller person in front, which gives the counts 0, 1, 2 and 3.
Example 3
heights = [3,1,2]tallerInFront = [0,0,0]return = [1,2,3]Nobody has a taller person in front, so the line must go from shortest to tallest: [1, 2, 3].
Constraints
n == heights.length == tallerInFront.length1 <= n <= 20001 <= heights[i] <= 10^9- All values in
heightsare different. 0 <= tallerInFront[i] <= n - 1tallerInFront[i]is at most the number of people taller than personi.
More Nutanix Online Assessment questions
- Good SubsequencesOA · Seen Jul 2026
- Min Cost to Connect All PointsOA · Seen Jun 2026
- Digit Changes for a Multiple of 9OA · Seen Aug 2025
- Gas Station Loop StartOA · Seen Aug 2025
- Number of Players (for MTS2)OA · Seen Oct 2024
- Work Schedules (for MTS2)OA · Seen Oct 2024
- Minimum Operations to Convert ArrayOA · Seen Apr 2024
- No Adjacent CharactersOA · Seen Apr 2024
- Build a BST From a ListOA · Seen Nov 2022
- Delete Even-Valued Nodes From a Linked ListOA · Seen Nov 2022
Similar questions at other companies
- Maximum Interactive Team SizeMicrosoft · OAMicrosoft interview questions
- Linear InterpolatorTwo Sigma · OATwo Sigma interview questions
- Find Sum of BeautiesAmazon · OA
- Choose ContainersIMC Trading · OAIMC Trading interview questions
- Minimize Maximum Group DifferenceDRW · OADRW interview questions
- Maximum Riders in CarUber · OAUber interview questions
- Maximum Team SizeExpedia · OAExpedia interview questions
- Maximum Taxi EarningsWells Fargo · OAWells Fargo interview questions
- Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions
- Pizza Shop (Google Tokyo)Google · OAGoogle interview questions