MWC '15 #1 P3: Dolls

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 256M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

MathBunny123 has practically a gazillion dolls. Unfortunately, he has so many that some of them are duplicates and he didn't even notice. A universal doll scanner has scanned his room and generated a list of the prices of the dolls. Given a list of the prices, determine the difference between the price of the most frequent doll, and the least frequent doll.
Note: If there are multiple dolls of the highest frequency, use the one with the greatest price, and if there are multiple dolls of the lowest frequency, use the one with the lowest price.

Input Specification

The first line will contain an integer N (1 \le N \le 1\,000\,000) the number of dolls that MathBunny123 has in his room.
The second line will contain the N integers, separated by spaces, representing the prices, P (1 \le P \le 100), of the dolls.

Output Specification

Output the absolute difference between the price of the most frequent doll, and the price of the least frequent doll.

Sample Input

10 20 10 40 40 40

Sample Output


Explanation for Sample Output

The most frequent doll is 40 and the least frequent is 20. The difference between the two numbers is 20.


  • -2
    nicktpls  commented on March 17, 2016, 1:58 p.m.

    is MathBunny123 a furry

  • 0
    richardyi25  commented on March 15, 2016, 10:36 a.m.

    The second line of input has a trailing space that might break certain input methods

    • 0
      aurpine  commented on March 15, 2016, 2:23 p.m. edited

      The problem author is looking into the issue. In the meantime, the issue shouldn't affect your program (have a for loop through 1 .. N to read input).

      Edit: Issue fixed.

  • -1
    aurpine  commented on March 14, 2016, 12:58 a.m.

    Problem statement updated for clarity! Sorry for any inconvenience this may have caused.