Amazon Interview Question
Backend DevelopersCountry: United States
public static int smallestCycle(int [] arr){
if(arr.length==0|| arr==null) return 0;
Set<Integer> set = new HashSet<Integer>();
int length=0;
int count=0;
for(int i=0;i<arr.length;i++){
if(!set.contains(arr[i])){
set.add(arr[i]);
length = length + count +1;
count=0;
}else{count++;}
}
return length;
}
can you elaborate better ? what do you mean by the list is not in repeat ?
- guilhebl April 18, 2018