Problem · Array

Rank Open Businesses

EasyMicrosoftFULLTIMEPHONE SCREEN
See Microsoft hiring insights

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
drafts saved locally
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