Runner-Up per Row
For each row of grid, find the second largest value in that row, counting repeats separately (so in [7, 7, 1] it is 7). Return the results as a list, one per row. Every row has at least 2 columns.
Example 1
grid [[5,9,2],[4,4,1]]
returns [5,4]
Row 0 sorted is 2, 5, 9 so the runner-up is 5. Row 1 sorted is 1, 4, 4 so it is 4.
Constraints
1 <= rows <= 102 <= columns <= 10
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Running Total per ColumnEasy
- Scale to Zero OneEasy
- Second LargestEasy
- Smallest PositiveEasy
- Softmax WeightsEasy
- Sort Each RowEasy
- Strong RowsEasy
- Total Over LimitEasy