The Lucky Employee

Summer is over and people at Gugol are sad and unmotivated. They would prefer going back on vacation instead of working - how to blame them? Ted, head of employee happiness department, has got an idea to cheer people up: he will run a lottery among all the employees and will award the luckiest one with two extra weeks of vacation. The lottery will work this way: Ted will raffle off some ranges of employee ids like \( [120, 200] \) and \( [150, 180] \), a sophisticated algorithm will calculate which is the most frequent employee id in all such ranges, if more than one such an id exists, the sophisticated algorithm will select the smallest one - it corresponds to the employee who has been working at Gugol for more time You are a \( \cancel{slave} \) trainee at Gugol and you have to design and write such a sophisticated algorithm. [Read More]

The Most Frequent

You are given an array of N integers separated by spaces, all in one line. Display the element which occurs most frequently. If multiple elements satisfy this criteria, display the numerically smallest one. Input Format The first line contains the number of integers \(N\). The second line contains space separated integers \(xi\) for which you need to find the most frequent one. Constraints \(10 \leq N \leq 1'000'000 \) \(0 \leq xi \leq 100'000 \) Output Format One line containing the result. [Read More]

The Product Name

Solutions Basically, each character \(out_i\) of the output string \(out\) occurs the least number of times at index \(i\) among all the input strings. We can count the occurrences of each letter of the alphabet (26) for each position of the input strings. Since all the strings have \(5\) characters, we have \(5\) frequency tables. Thus, we use constant additional storage - for instance, an array containing 5 arrays of 26 integers. [Read More]