Rank Open Businesses
Updated
Problem statement
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.
Function
rankOpenBusinesses(candidates: int[][], k: int) → int[]Examples
Example 1
candidates = [[90,4,1],[95,8,0],[90,2,1],[85,1,1]]k = 2return = [2,0]Candidate 1 is closed. Candidates 2 and 0 tie on score, so the smaller distance comes first.
Example 2
candidates = [[80,3,1],[80,2,1],[90,10,1]]k = 5return = [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
kbusinesses are open, return all open businesses in ranked order.
More Microsoft Phone Screen questions
- Config Store with Priority OverridesPHONE SCREEN · Seen Nov 2026
- Corporation Reporting LinesPHONE SCREEN · Seen Oct 2026
- Random Forest Classifier from ScratchPHONE SCREEN · Seen Oct 2026
- Least Recently Used CacheOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Greedy and Beam Sentence DecodingPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Top K Frequent ElementsPHONE SCREEN · Seen Sep 2026
- 3SumPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Arithmetic Expression EvaluatorPHONE SCREEN · Seen Sep 2026
- Employee Hierarchy Cycle and Depth AnalysisPHONE SCREEN · Seen Sep 2026
- Most Visited String SectorsPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Total Years of Work ExperienceLinkedIn · PHONE SCREENLinkedIn interview questions
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Squares of a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
- Assign CookiesAmazon · PHONE SCREEN
- Sort by Checking PermutationsMercor · PHONE SCREENMercor interview questions
- Meeting RoomsGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Parse and Sort Integer DataLegora · PHONE SCREEN
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)