Trains the technique from
LeetCode 1152Analyze User Website Visit PatternThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
An app's analytics log has one row per screen opening. Row i says that viewer viewer[i] opened screen screen[i] at clock reading moment[i]. The rows arrive in no particular order.
Put each viewer's own rows into increasing order of clock reading; when two of that viewer's rows share a reading, the one listed earlier in the input goes first. That gives every viewer a single ordered walk through the app.
A trail is a sequence of exactly three screen names. A viewer follows a trail when three rows can be picked out of their walk, at strictly increasing places in it, whose screen names spell the trail in order. The three places need not be next to each other, and the same screen name may appear more than once in a trail if the viewer opened that screen more than once. A viewer either follows a trail or does not; the number of different ways they could pick the rows makes no difference.
Return the trail followed by the greatest number of viewers, as a list of its three screen names. When several trails are followed by that many viewers, return the alphabetically smallest of them, comparing the three names in order.
Example 1
Each of the two viewers follows exactly one trail, and the two trails differ, so both are followed by one viewer and the alphabetical rule settles it.
Example 2
Two viewers walk the same three screens in the same order. The third viewer has only two rows in the log, so no trail is credited to them.
Example 3
One viewer owns the whole log, so every trail they follow is followed by exactly one viewer and the alphabetically smallest of those trails is returned.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def busiest_trail(viewer: list[str], moment: list[int], screen: list[str]) -> list[str]:public List<String> busiestTrail(String[] viewer, int[] moment, String[] screen)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.