-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.c
47 lines (35 loc) · 908 Bytes
/
random.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<stdio.h>
int solution(int A[],int N)
{
int flag[100001]={0};
int bounce=0,i=0;
while(i>=0&&i<N)
{
flag[i]=1;
i=i+A[i];
if(flag[i]==1)
{
bounce=-1;
break;
}
bounce++;
}
return bounce;
}
int main()
{
int arr[100001],N,cases,i,result;
printf("enter # of test cases\n");
scanf("%d",&cases);
while(cases--)
{
printf("Enter the size of array\n");
scanf("%d",&N);
printf("Enter values of elements\n");
for(i=0;i<N;i++)
scanf("%d",&arr[i]);
result=solution(arr,N);
printf("%d\n",result);
}
return 0;
}