FastPrepFastPrep
Problem Brief

Rank Open Businesses

FULLTIMEPHONE SCREEN
See Microsoft online assessment and 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.

1Example 1

Input
candidates = [[90,4,1],[95,8,0],[90,2,1],[85,1,1]], k = 2
Output
[2,0]
Explanation

Candidate 1 is closed. Candidates 2 and 0 tie on score, so the smaller distance comes first.

2Example 2

Input
candidates = [[80,3,1],[80,2,1],[90,10,1]], k = 5
Output
[2,1,0]
Explanation

All open stores are returned because fewer than five stores are available.

Constraints

Limits and guarantees your solution can rely on.

Closed businesses must not appear in the result. If fewer than k businesses are open, return all open businesses in ranked order.

public int[] rankOpenBusinesses(int[][] candidates, int k) {
    // write your code here
}
Input

candidates

[[90,4,1],[95,8,0],[90,2,1],[85,1,1]]

k

2

Output

[2,0]

Sign in to submit your solution.