Best Columns of Each Row
Return, for each row of scores, the column numbers of its k largest values, largest first. Among equal values the lower column comes first. No loops: for and while are not allowed.
Example 1
scores [[3,9,3,7],[5,5,1,5]]
k 2
returns [[1,3],[0,1]]
Row 0: 9 is in column 1, then 7 in column 3. Row 1: three 5s tie, and columns 0 and 1 come first.
Constraints
1 <= k <= columns <= 121 <= rows <= 200 <= scores[r][c] <= 9
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Cells Above Row AverageMedium
- Count Local PeaksMedium
- Deepest Fall From a HighMedium
- Distance From a CellMedium
- Halfway PointMedium
- Highest Cell PositionMedium
- Matching PairsMedium
- Mean of Each GroupMedium