Where is the mistake? Finding majority
<p>I want to find the majority in array (number that appears most of the time).
I have a sorted array and use these cycles:</p>

<pre><code>for(int k = 1;k &lt; length;k++)
{
    if(arr[k-1] == arr[k])
    {
        count++;
        if(count &gt; max)
        {
            max = count;
            maxnum = arr[k-1];
        }
    } else {
        count = 0;
    }
}
</code></pre>

<p>or</p>

<pre><code>for(int h=0;h&lt;length;h++)
{
    for(int l=1;l&lt;length;l++)
    {
        if(arr[h] == arr[l])
        {
            count++;
            if(count &gt; max)
            {
                max = count;
                maxnum = arr[h];
            }
        } else count = 0;
    }
}
</code></pre>

<p>they are similiar. When i try them on small arrays everything seems to be ok. But on a long run array with N elements 0&lt;=N&lt;=500000, each element K 0&lt;=K&lt;=10^9 they give wrong answers. 
Here is solution with mistake <a href="http://ideone.com/y2gvnX" rel="nofollow">http://ideone.com/y2gvnX</a>. I know there are better algos to find majority but i just need to know where is my mistake.</p>

<p>I really can't find it :( Will really appreciate help!</p>
