Ctrl K

Places in the Lineup

Easy
The heights of students in a class are stored in heights. The teacher lines the class up by height, shortest first, with places numbered from zero. Return every place that will be taken by a student whose height is exactly wanted, in increasing order. If there is no such student, return an empty list.
Example 1
heights=[7, 3, 7, 5, 1], wanted=7 → [3, 4]

Sorted, the list becomes [1, 3, 5, 7, 7]: the value 7 sits at positions 3 and 4.

Example 2
heights=[4, 2, 9], wanted=2 → [0]

The sorted array is [2, 4, 9], and 2 comes first.

Example 3
heights=[6, 6, 8], wanted=5 → []

There is no 5 in the array, so the answer is empty.

Constraints
  • 1 ≤ len(heights) ≤ 100
  • 1 ≤ heights[i], wanted ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Lost Ticket EasyValues in Both Lists EasyShared Values With Repeats EasyEven Out the Shelves EasyBest Pair Under the Limit Easy
loading Python…
Input
heights=[7, 3, 7, 5, 1], wanted=7
Expected
[3, 4]

Run checks the first 3 tests in your browser. Submit checks all 118 tests on the server, hidden ones included.