Each business candidate is represented as [score, distance, isOpen], where isOpen is 1 for open and 0 for closed. Return the indices of the top k open businesses.
Open businesses should be sorted by descending score. If two businesses have the same score, the one with the smaller distance comes first. If both score and distance are tied, keep the smaller original index first.
Examples
01 · Example 1
candidates = [[90,4,1],[95,8,0],[90,2,1],[85,1,1]] k = 2 return = [2,0]
Candidate 1 is closed. Candidates 2 and 0 tie on score, so the smaller distance comes first.
02 · Example 2
candidates = [[80,3,1],[80,2,1],[90,10,1]] k = 5 return = [2,1,0]
All open stores are returned because fewer than five stores are available.
Constraints
Closed businesses must not appear in the result. If fewer than k businesses are open, return all open businesses in ranked order.
More Microsoft problems
- Retain Top K ValuesPHONE SCREEN · Seen May 2026
- In-Memory SQL with CSV InitializationONSITE INTERVIEW · Seen May 2026
- Order Records by Matching Start and EndONSITE INTERVIEW · Seen May 2026
- Recover Corrupted Master PageONSITE INTERVIEW · Seen Feb 2026
- Distinct Number Line MovesOA · Seen Oct 2025
- Get Minimum TimeSeen Jun 2025
- Count Subarrays with Bitwise OR PresentSeen Jun 2025
- Get Max Or SumSeen Jun 2025
public int[] rankOpenBusinesses(int[][] candidates, int k) {
// write your code here
}
candidates[[90,4,1],[95,8,0],[90,2,1],[85,1,1]]
k2
expected[2,0]
sign in to submit