FastPrepRebuild the Line From Taller-in-Front Counts
Problems/Rebuild the Line From Taller-in-Front Counts

Rebuild the Line From Taller-in-Front Counts

Nutanix logoNutanix● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Nutanix campus report for interns calls the first of two coding-test questions a binary search problem with two kinds of queries. It says only an O(n log n) answer passed every test. A later report that seems to describe the same set of rounds explains the approach to its first question: sort people by height and put each one into the right free spot in a queue. That points to this classic task.

Neither report gives the statement. The two kinds of queries do not clearly fit this task, so that part is still unresolved and is not tested here. This version uses the usual rules. All heights are different. Each count is the number of taller people in front. The input always matches exactly one line. You return the heights from front to back. The sizes are our choice too: 1 to 2000 people, so the answer list stays short, and heights from 1 to 10^9.

Our version is about 50% the same as the reported questions.

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.length
  • 1 <= n <= 2000
  • 1 <= heights[i] <= 10^9
  • All values in heights are different.
  • 0 <= tallerInFront[i] <= n - 1
  • tallerInFront[i] is at most the number of people taller than person i.

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

Interview reports that mention this question

  • Nutanix Intern Debugging Round and Interviews: 25 Experiences

Nutanix interview experiences

  • Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)
  • Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)
  • Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
  • Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
All Nutanix interview questionsSee Nutanix hiring insights
Saved
class Solution {
    public int[] orderOfPeople(int[] heights, int[] tallerInFront) {
        // Write your code here.
    }
}
Checking account…