forked from srinathr91/TestJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
36 lines (33 loc) · 904 Bytes
/
Solution.java
File metadata and controls
36 lines (33 loc) · 904 Bytes
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
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int X, int[] A) {
// count==x for a path
Boolean[] fall=new Boolean[X];
for(int i=0; i<X; i++){
fall[i]=false;
}
int count=0;
int ans=-1;
//checking the path
for(int j=0;j<A.length;j++){
if(fall[A[j]-1]==false){
fall[A[j]-1]=true;
++count;
if(count==X){
ans=j;
break;
}
}
}
return ans;
}
public static void main(String[] args){
Solution sol=new Solution();
int X=5;
int[] A={1,3,1,4,2,3,5,4};
System.out.println(sol.solution(X, A));
}
}