Skip to content

Instantly share code, notes, and snippets.

@axayjha
Last active August 25, 2017 18:09
Show Gist options
  • Save axayjha/a96c260ea7e33f1c8a147d8ab97d083f to your computer and use it in GitHub Desktop.
Save axayjha/a96c260ea7e33f1c8a147d8ab97d083f to your computer and use it in GitHub Desktop.
#include <stdio.h>
int find(int, int);
int main()
{
int n, k;
scanf("%d %d", &n, &k);
int c = find(n,k);
printf("%d\n", c);
}
int find(int n, int k)
{
int number, i=0, count=0, index=-1;
while(scanf(" %d", &number) && number!=-1)
{
if(number==n)
{
index=i;
if(++count ==k) break;
}
i++;
}
if (count!=k) return -1;
return index;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment