FastPrepBeautiful Row
Problems/Beautiful Row

Beautiful Row

Nutanix logoNutanix● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two reports from Nutanix intern online assessments in early 2020 include this question. One only gives its name, Beautiful Row. The other also says it is the longest bitonic subsequence. It outlines the usual method: join the longest rising part and the longest falling part that meet at the same peak.

Neither report gives a story, an input format, limits or examples. Here the input is a list of heights. Both the rise and the fall must be strict. A row that only rises or only falls also counts. The row has at most 1000 people. The examples are our own.

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

People stand in a row. The height of person i is heights[i].

You may send away any of the people. Everyone who stays keeps their place in the original order. The people who stay form a beautiful row if their heights first strictly go up and then strictly go down. That is, one person is the peak: each person up to the peak is taller than the person before them, and each person after the peak is shorter than the person before them.

  • Either part may be empty. A row that only goes up, a row that only goes down, and a single person are all beautiful.
  • Two neighbors in a beautiful row never have the same height.

Return the largest number of people that can stay and still form a beautiful row.

Function

longestBeautifulRow(heights: int[]) → int

Examples

Example 1

heights = [1,4,2,6,5,3]return = 5

Keep the heights 1, 4, 6, 5, 3 and leave out 2. They go up from 1 to 4 to 6, then down from 6 to 5 to 3, so the row is beautiful and has 5 people. Keeping all six does not work: the heights go down from 4 to 2 and then up again to 6. So the answer is 5.

Example 2

heights = [5,4,4,3]return = 3

Keep 5, 4, 3. The heights only go down, which is allowed: the going-up part is just the first person. Both 4s cannot be kept, because two neighbors in a beautiful row must have different heights. So the answer is 3.

Example 3

heights = [3,3,5,7]return = 3

Keep 3, 5, 7, using either of the two 3s. The heights only go up, which is allowed: the going-down part is just the last person. The two 3s cannot both be kept. So the answer is 3.

Constraints

  • 1 <= heights.length <= 1000
  • 1 <= heights[i] <= 10^9

Interview reports that mention this question

  • Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)

Nutanix interview experiences

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