title: Having mistakes with Java Hashtable for a big input
body: <p>I'm making a code for this <a href="https://www.hackerrank.com/challenges/migratory-birds/problem" rel="nofollow noreferrer">HackerRank</a>, using <code>Hashtable</code>. My code passes the first 4 first input test, but when I try with the final one, the biggest, it reports a wrong answer.</p>
  <p>This is my code:</p>
  <pre><code>import java.io.*;
  import java.util.*;
  import java.text.*;
  import java.math.*;
  import java.util.regex.*;
  
  public class Solution {
  
      static int migratoryBirds(int n, int[] ar) {
          Hashtable&lt;Integer,Integer&gt; birds = new Hashtable&lt;Integer,Integer&gt;();
          for (int i=0;i&lt;n;i++) {
              if (birds.get(ar[i])==null) {
                  birds.put(ar[i],1);
              } else {
                  birds.put(ar[i],birds.get(ar[i])+1);
              }
          }
          Set&lt;Integer&gt; keys = birds.keySet();
          int maxKey = 0;
          int maxValue = 0;
          for (Integer key : keys) {
              if ((maxKey==0 &amp;&amp; maxValue==0) || maxValue&lt;birds.get(key)) {
                  maxValue = birds.get(key);
                  maxKey = key;
              }           
          }
          return maxKey;
      }
  
      public static void main(String[] args) {
          Scanner in = new Scanner(System.in);
          int n = in.nextInt();
          int[] ar = new int[n];
          for(int ar_i = 0; ar_i &lt; n; ar_i++){
              ar[ar_i] = in.nextInt();
          }
          int result = migratoryBirds(n, ar);
          System.out.println(result);
      }
  }
  </code></pre>
  <p>And <a href="https://hr-testcases-us-east-1.s3.amazonaws.com/33294/input04.txt?AWSAccessKeyId=AKIAJ4WZFDFQTZRGO3QA&amp;Expires=1522959331&amp;Signature=%2Bh6CiMYzKnzFSahLpWN3HKfk%2Bhs%3D&amp;response-content-type=text%2Fplain" rel="nofollow noreferrer">this</a> is the input (it's big).</p>
  <p>Can anyone tell me why is this wrong?</p>