FastPrepMost Visited Hotel in a Time Window
Problems/Most Visited Hotel in a Time Window

Most Visited Hotel in a Time Window

Motive logoMotive● MediumFULLTIMEONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A first-hand Motive interview report describes a CSV of user, hotel, and arrival time and asks which hotel has the most users in a supplied time range. Distinct-user counting, inclusive bounds, and lexicographic ties are explicit practice assumptions; the reported core matches at about 90%.

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) → String

Examples

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 0 through 100000.
  • User IDs and hotel names are non-empty ASCII strings.
  • -1000000000 <= timestamps[i], startTime, endTime <= 1000000000 and startTime <= 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
All Motive interview questionsSee Motive hiring insights
Saved
class Solution {
    public String mostVisitedHotel(String[] userIds, String[] hotels, int[] timestamps, int startTime, int endTime) {
        // write your code here
    }
}
Checking account…