Skip to content

Instantly share code, notes, and snippets.

@nagy3n
Created July 20, 2015 13:09
Show Gist options
  • Save nagy3n/9a0306212c3cd9efa581 to your computer and use it in GitHub Desktop.
Save nagy3n/9a0306212c3cd9efa581 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int times[1000001],indst[1000001],inden[1000001],n,i,f,maxn,max;
maxn=-1;
scanf("%d",&n);
memset(times, 0, 1000001*sizeof(int));
for(i=0;i<n;i++)
{
scanf("%d",&f);
times[f]+=1;
if(times[f]==1)
indst[f]=i+1;
inden[f]=i+1;
if(times[f]>maxn)
{
max=f;
maxn=times[f];
}
else if(times[f]==maxn)
{
if((inden[max]-indst[max])>(inden[f]-indst[f]))
max=f;
}
}
printf("%d %d",indst[max],inden[max]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment