Most Widely Shared Three-Visit Website Pattern

Quick Overview

Most Widely Shared Three-Visit Website Pattern. Parallel arrays username, timestamp and website describe visits.

Most Widely Shared Three-Visit Website Pattern

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Parallel arrays username, timestamp and website describe visits. A pattern is an ordered list of three websites, which may repeat. Its score is the number of distinct users having visits to those sites in that chronological order, with other visits allowed between them. Return the highest-scoring pattern; break a score tie by lexicographic order of the three site strings. **Practice assumption:** A pattern's visits must have strictly increasing timestamps, and at least one user has a valid three-visit sequence. Equal-time visits are allowed, including for the same user, but cannot form an ordered pair. ```cpp class Solution { public: vector<string> mostVisitedPattern(vector<string>& username, vector<int>& timestamp, vector<string>& website); }; ``` ### Examples **Example 1:** ```text Input: username = ["u","u","u","v","v","v"], timestamp = [1,2,3,4,5,6], website = ["a","c","b","a","c","b"] Output: ["a","c","b"] Explanation: Both users follow this three-site pattern, giving score2. ``` **Example 2:** ```text Input: username = ["p","p","p","p"], timestamp = [1,2,3,4], website = ["b","a","c","d"] Output: ["a","c","d"] Explanation: Every available triple has score1. The only triple starting with a is lexicographically smallest. ``` ### Constraints - All three arrays have equal length N, with `3 <= N <= 50`. - User and website strings have length 1 to 10 and use lowercase English letters. - Timestamps are integers in `[1,1000000000]`. - Every (user,timestamp,website) tuple is unique. - At least one user has three visits with strictly increasing timestamps. ### Contract considerations Preserve all three original arrays and the vector-of-three-strings result. Do not assume all timestamps, or all of one user's timestamps, are distinct. ```hint Read the boundary condition Does one user's repeated realization of a pattern add several users to its score, and can equal-time visits supply consecutive pattern entries? ``` ### Boundary reminders Preserve all three original arrays and the vector-of-three-strings result. Do not assume all timestamps, or all of one user's timestamps, are distinct.

Overview: Most Widely Shared Three-Visit Website Pattern. Parallel arrays username, timestamp and website describe visits.

Amazon logo
Amazon
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Parallel arrays username, timestamp and website describe visits. A pattern is an ordered list of three websites, which may repeat. Its score is the number of distinct users having visits to those sites in that chronological order, with other visits allowed between them. Return the highest-scoring pattern; break a score tie by lexicographic order of the three site strings.

Practice assumption: A pattern's visits must have strictly increasing timestamps, and at least one user has a valid three-visit sequence. Equal-time visits are allowed, including for the same user, but cannot form an ordered pair.

class Solution {
public:
    vector<string> mostVisitedPattern(vector<string>& username, vector<int>& timestamp, vector<string>& website);
};

Examples

Example 1:

Input: username = ["u","u","u","v","v","v"], timestamp = [1,2,3,4,5,6], website = ["a","c","b","a","c","b"]
Output: ["a","c","b"]
Explanation: Both users follow this three-site pattern, giving score2.

Example 2:

Input: username = ["p","p","p","p"], timestamp = [1,2,3,4], website = ["b","a","c","d"]
Output: ["a","c","d"]
Explanation: Every available triple has score1. The only triple starting with a is lexicographically smallest.

Constraints

  • All three arrays have equal length N, with 3 <= N <= 50 .
  • User and website strings have length 1 to 10 and use lowercase English letters.
  • Timestamps are integers in [1,1000000000] .
  • Every (user,timestamp,website) tuple is unique.
  • At least one user has three visits with strictly increasing timestamps.

Contract considerations

Preserve all three original arrays and the vector-of-three-strings result. Do not assume all timestamps, or all of one user's timestamps, are distinct.

Boundary reminders

Preserve all three original arrays and the vector-of-three-strings result. Do not assume all timestamps, or all of one user's timestamps, are distinct.