Most Visited Hotel in a Time Window
Updated
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.
More Motive Onsite Interview questions
- Group AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
- Longest Equal-Zero-One SubarrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
- Maximum Weighted Sum After Left RotationsONSITE INTERVIEW · Seen Jan 2026
- Valid Parenthesis StringPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
- Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Dec 2025
- Target Triplet SumONSITE INTERVIEW · Seen Dec 2025
- Validate IP AddressONSITE INTERVIEW · Seen Dec 2025
- Generate Palindromic PermutationsONSITE INTERVIEW · Seen Dec 2025
- Minimum Swaps to Group Circular OnesONSITE INTERVIEW · Seen Dec 2025
- Staircase Search In A Sorted MatrixONSITE INTERVIEW · Seen Dec 2025
Similar questions at other companies
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
- Group AnagramsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Top K Frequent ElementsCapgemini · ONSITE INTERVIEWCapgemini interview questions
- Find Duplicate Element PairsGoogle · ONSITE INTERVIEWGoogle interview questions
- Top-K URLs Overall and in the Last 24 HoursOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- Read a File from Distributed ChunksHudson River Trading · ONSITE INTERVIEWHudson River Trading interview questions
- Top K Frequent ElementsInfosys · ONSITE INTERVIEWInfosys interview questions