FastPrepTravelers per Consecutive City Triplet
Problems/Travelers per Consecutive City Triplet

Travelers per Consecutive City Triplet

Uber logoUber● MediumFULLTIMEONSITE INTERVIEW

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported from an Uber onsite interview (full-time machine learning engineer, applied online) by a candidate with a PhD who was changing jobs.

In short, the interviewer gives a log of trips, one row per trip with who traveled, when, and to which city, and the rows are not said to be sorted. Three cities that the same person visited one after another form a triplet, and the task is to report, for each triplet in the log, how many different people have it. The candidate sorted the trips by time and counted with a hash map. A follow-up asked what to do when the log does not fit in memory, and the discussion went to splitting the data by traveler or by city and running a MapReduce job, with the trips still needing to be in time order. That follow-up is covered in the editorial and is not tested.

The report gives no function name, input format, output format, limits or examples. The names countTripletTravelers, travelers, timestamps and destinations, the three arrays of the same length, the timestamps of one traveler all being different, the limits, the output rows with the count as a string and their alphabetical order, and the examples are our choices.

Our version is about 90% the same as the reported question.

A trip log has n rows. Row i says that the traveler travelers[i] traveled to the city destinations[i] at time timestamps[i]. The rows are not in any particular order.

Put the trips of one traveler in time order. Every three cities that this traveler visited one right after another form a triplet (cityA, cityB, cityC).

For every triplet that appears in the log, count the number of different travelers who have it. A traveler who has the same triplet more than once still counts once.

Return one row [cityA, cityB, cityC, count] for each triplet, with the count written as a decimal string. Sort the rows by cityA, then by cityB, then by cityC. If there is no triplet, return an empty array.

Function

countTripletTravelers(travelers: String[], timestamps: int[], destinations: String[]) → String[][]

Examples

Example 1

travelers = ["ann","bob","ann","bob","ann","bob","ann"]timestamps = [3,7,1,2,4,5,2]destinations = ["oslo","oslo","paris","paris","paris","rome","rome"]return = [["paris","rome","oslo","2"],["rome","oslo","paris","1"]]

Sorted by time, ann goes to paris, rome, oslo, paris, so her triplets are (paris, rome, oslo) and (rome, oslo, paris). Bob goes to paris, rome, oslo, so his only triplet is (paris, rome, oslo). Two travelers have (paris, rome, oslo) and one has (rome, oslo, paris).

Example 2

travelers = ["dan","eve","dan","dan","eve","dan","dan"]timestamps = [10,4,30,20,9,40,50]destinations = ["tokyo","lima","tokyo","seoul","quito","seoul","tokyo"]return = [["seoul","tokyo","seoul","1"],["tokyo","seoul","tokyo","1"]]

Dan goes to tokyo, seoul, tokyo, seoul, tokyo. His triplets are (tokyo, seoul, tokyo), (seoul, tokyo, seoul) and (tokyo, seoul, tokyo) again. Dan is one traveler, so (tokyo, seoul, tokyo) has a count of 1, not 2. Eve has only two trips, so she has no triplet.

Example 3

travelers = ["kim","lee","kim"]timestamps = [5,5,8]destinations = ["cairo","dubai","delhi"]return = []

No traveler has three trips, so there is no triplet and the answer is empty.

Constraints

  • 1 <= n <= 2000, where n is the length of travelers, timestamps and destinations
  • 1 <= travelers[i].length, destinations[i].length <= 10
  • travelers[i] and destinations[i] consist of lowercase English letters.
  • 0 <= timestamps[i] <= 109
  • The timestamps of any one traveler are all different.

More Uber Onsite Interview questions

  • Random Bingo Card GeneratorONSITE INTERVIEW · Seen Dec 2026
  • Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Online Meeting Scheduler with Fixed RoomsONSITE INTERVIEW · Seen Oct 2026
  • Minimum Meeting Rooms with AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Serialize and Deserialize an N-Ary TreeONSITE INTERVIEW · Seen Oct 2026
  • Longest Continuous Subarray Within an Absolute-Difference LimitONSITE INTERVIEW · Seen Oct 2026
  • K Smallest Squares from a Sorted ArrayONSITE INTERVIEW · Seen Sep 2026
  • Grid Robot Route with Charging PrioritiesPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Shortest Increasing Path to a TargetONSITE INTERVIEW · Seen Sep 2026
  • My Calendar IONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
  • Group AnagramsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Find Duplicate Element PairsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Group Duplicate Files by ContentPostman · ONSITE INTERVIEWPostman interview questions
  • Group AnagramsGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Group AnagramsMotive · PHONE SCREEN · ONSITE INTERVIEWMotive interview questions
  • Group AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Group AnagramsExpedia · ONSITE INTERVIEWExpedia interview questions
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public String[][] countTripletTravelers(String[] travelers, int[] timestamps, String[] destinations) {
        // Write your code here.
    }
}
Checking account…