Given an array of integers, return the index of one of the largest elements, chosen uniformly at random.
Example:
index: 0 1 2 3 4 5 6
array: [5, 3, 6, 6, 0, 2, 6]
should return 2, 3, or 6, each with probability 1/3
You are given a list of web pages, with each edge indicating a transition from the prior page to the next page. We want the most frequent sequence of 3 pages.
Example:
input: [A, B, A, B, A, C, B, A]
seqs: ABA, BAB, ABA, BAC, ACB, CBA
A => youtube.com
B => google.com
C => facebook.com
We would want ABA since that sequence occurs twice.
This prompt combines two common interview patterns. The first asks for a uniformly random index among all maximum elements, which is typically solved by scanning for the maximum value and then randomly selecting one of its positions. The second asks for the most frequent sequence of 3 web pages in a browsing history, which is a straightforward sliding-window counting problem using a hash map. The key idea is to count every consecutive triple and return the one with the highest frequency.