Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Aloyna and Can Buying

By prodip_bsmrstu · Limits 1s, 512 MB

Aloyna is a can lover girl and whenever she goes to a shop, she must buy a can to drink. This time she goes to a shop to buy a can. There are nn cans in the shop of kk types. The types are numbered from 11 to kk.

She will buy a specific type of can if the quantity of this type of can is the maximum in the shop. Can you find which type of can Aloyna will buy?


In the first line, there will be 2 integers nn (1n10001 \le n \le 1000) and kk (1k1001 \le k \le 100).

In the next line, there will be n integers, a1a_1, a2a_2, a3a_3, ..., ana_n (1aik1 \le a_i \le k), the types of each can in the shop.


Print a number, the type number of the can which Aloyna will buy from the shop. If there are multiple answers then choose the can whose type number is minimum.


6 3
1 2 2 2 1 3

There are 6 cans of 3 types and type #1's quantity is 2, type #2's quantity is 3 and type #3's quantiy is 1. Since type #2's quantity is the maximum, so the answer is 2.

3 3
1 2 3

Since every type's quantity is the same, so the answer is the can whose type number is minimum which is 1 in this case.



87% Solution Ratio

iammarajulEarliest, Dec '19

iammarajulFastest, 0.0s

RubiathLightest, 0 B

bokaifShortest, 78B


Login to submit


Just count the occurrences of every type and print the max occurring one.

Toph uses cookies. By continuing you agree to our Cookie Policy.