Most Visited Hotel in a Time Window
Problem statement
Each index describes one hotel visit by userIds[i] to hotels[i] at integer timestamp timestamps[i].
Among visits whose timestamp is in the inclusive interval [startTime, endTime], return the hotel visited by the largest number of distinct users. Break a tie by returning the lexicographically smallest hotel name. Return the empty string when the interval contains no visit.
Function
mostVisitedHotel(userIds: String[], hotels: String[], timestamps: int[], startTime: int, endTime: int) → StringExamples
Example 1
userIds = ["u1","u2","u1","u3"]hotels = ["A","A","A","B"]timestamps = [10,20,25,30]startTime = 10endTime = 30return = "A"Hotel A has two distinct users; repeated visits by u1 count once.
Example 2
userIds = ["u1","u2"]hotels = ["Beta","Alpha"]timestamps = [5,6]startTime = 0endTime = 10return = "Alpha"Both hotels have one user, so the lexicographically smaller name wins.
Constraints
- All three arrays have the same length from
0through100000. - User IDs and hotel names are non-empty ASCII strings.
-1000000000 <= timestamps[i], startTime, endTime <= 1000000000andstartTime <= endTime.