void main() {
// return reoccured number
//Google Question
List array = [2,5,5,2,3,5,1,2,4];
//It should return 2
List array1 = [2,1,1,2,3,5,1,2,4];
//It should return 1
List array2 = [2,3,4,5];
//It should return undefined
// detect 5 and 5 firast
//[2,5,5,2,3,5,1,2,4];
firstRecurringCharacter0(input) {
List temp = [];
for (var i = 0; i < input.length; i++) {
int count = 0;
for (var j = i + 1; j < input.length; j++) {
if(input[i] == input[j]) {
count++ ;
if(count ==2){
return input[j];
}
}
}
}
return 'undefined';
}
String firstRecurringCharacter(input) {
List tempList = [];
String value = 'undefined';
for(var i = 0; i < input.length; i++){
if(tempList.contains(input[i])){
value = input[i].toString();
break;
}else{
value = 'undefined';
}
tempList.add(input[i]);
}
return value;
}
String firstRecurringCharacter1(input) {
Map tempList = {};
String value = 'undefined';
for(var i = 0; i < input.length; i++){
print(tempList);
if(tempList.containsKey(input[i])){
value = input[i].toString();
break;
}else{
value = 'undefined';
}
tempList[input[i]] = i;
}
return value;
}
print(firstRecurringCharacter0(array));
//Bonus... What if we had this:
// [2,5,5,2,3,5,1,2,4]
// return 5 because the pairs are before 2,2
}