Unique Elements

View as PDF

Submit solution

Points: 4 (partial)
Time limit: 5.0s
Memory limit: 64M

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

Given a list of N (1 \le N \le 30\,000) positive integers less than or equal to 10^9, print out how many distinct numbers exist.

Input Specification

The first line will contain the integer N. The next N lines will contain an element in the list.

Output Specification

One integer: the number of distinct elements in the given list.

Sample Input 1


Sample Output 1


Sample Input 2


Sample Output 2



  • -2
    HyperFire12  commented on Oct. 23, 2019, 2:56 p.m. edited


  • -2
    KingT  commented on Dec. 3, 2018, 8:51 p.m. edited

    Can someone look at my solution. I don't understand why it isn't working.

    EDIT: Don't worry fixed the problem. Just needed to sort.

  • 3
    echofox  commented on July 21, 2018, 8:22 p.m. edit 2

    this is so sad


  • -2
    Oppenheimer  commented on Oct. 1, 2014, 5:31 p.m.

    You one-liners make me feel bad...

    • 0
      Xyene  commented on Oct. 1, 2014, 10:08 p.m.

      Hint: sets have very fast O(1) in checks, whereas lists have very slow O(n) in checks. Your solution will probably pass if you use a set, but you may have to combine your two for loops into one.

    • 2
      FatalEagle  commented on Oct. 1, 2014, 10:01 p.m.

      It appears that your solution doesn't have the intended complexity (the real testdata used to have N <= 20). As such, the limits have been increased and solutions have been rejudged :)