Problem · Array

Most Visited String Sectors

Learn this problem
EasyMicrosoft logoMicrosoftFULLTIMEPHONE SCREEN
See Microsoft hiring insights

Problem statement

A circular track is divided into distinct sectors whose string labels are given in clockwise order by sectors. A runner starts in rounds[0]. For each later label in rounds, the runner moves clockwise until reaching that sector.

Count the starting sector once and count each sector whenever the runner enters it. Return every sector with the maximum visit count, preserving the clockwise order in sectors.

Function

mostVisitedSectors(sectors: String[], rounds: String[]) → String[]

Examples

Example 1

sectors = ["north","east","south","west"]rounds = ["north","south","north","east"]return = ["north","east"]

North and east are each visited twice, while south and west are each visited once.

Example 2

sectors = ["red","blue","green"]rounds = ["green","blue"]return = ["red","blue","green"]

The clockwise trip from green to blue visits green, red, and blue once, so every sector ties.

Constraints

  • 2 <= sectors.length <= 100
  • 2 <= rounds.length <= 10^5
  • All sector labels are distinct, nonempty strings.
  • Every label in rounds appears in sectors.

More Microsoft problems

drafts saved locally
public String[] mostVisitedSectors(String[] sectors, String[] rounds) {
    // Write your code here
}
sectors["north","east","south","west"]
rounds["north","south","north","east"]
expected["north", "east"]
checking account