Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. // you can write to stdout for debugging purposes, e.g.
  2. // printf("this is a debug message\n");
  3.  
  4. int solution(int X, int A[], int N) {
  5. // write your code in C99 (gcc 6.2.0)
  6. int *pod = (int*)calloc( N + 1, sizeof(int));
  7. int nr_frunze = X;
  8.  
  9. if( N < X)
  10. return -1;
  11.  
  12. for(int i = 0; i < N; i++)
  13. {
  14. if( pod[ A[i] ] == 1)//exista deja element aici
  15. continue;
  16. pod[ A[i]] = 1;
  17. nr_frunze--;
  18. if(nr_frunze == 0)
  19. return i;
  20.  
  21. }
  22.  
  23. return -1;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement