What's the time complexity and auxiliary space for this method? Can anyone please tell and explain me the results?
public Set<T> findRepeatedValues(List<T> list){
Set<T> set = new HashSet<>();
Set<T> repeatedValues = new HashSet<>();
for (T i: list) {
if (!set.add(i)) {
repeatedValues.add(i);
}
}
return repeatedValues;
}
what happened if I Test my code like below?
@Test
public void findRepeatedStrings(){
List<String> stringList = new ArrayList<String>(Arrays.asList("ali","mahdi","hadi","mahdi","mojtaba","mohammad","mojtaba"));
RepeatedValues repeatedValues = new RepeatedValues();
Set values = repeatedValues.findRepeatedValues(stringList);
for (Object i :
values) {
System.out.println(i);
}
}