Skip to content

Commit d090cd6

Browse files
author
Wakidur Rahaman
committed
hash table question 01 solution 01 implement.
1 parent 24b6b1c commit d090cd6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Google Question
2+
/**
3+
* Given an array = [2, 5, 1, 2, 3, 5, 1, 2, 4]: It should return 2
4+
*
5+
* Given an array = [2, 1, 1, 2, 3, 5, 1, 2, 4]: It should return 1
6+
*
7+
* Given an array = [2, 3, 4, 5]: It should return undefined
8+
*
9+
*/
10+
11+
// Solution 01:
12+
function firstRecurringCharacter(array: number[]): number | undefined {
13+
for (let i = 0; i < array.length; i++) {
14+
const element = array[i];
15+
console.log('first : ', element);
16+
for (let j = i + 1; j < array.length; j++) {
17+
const element = array[j];
18+
console.log('Second : ', element);
19+
if (array[i] === array[j]) {
20+
console.log(array[i]);
21+
return array[i];
22+
}
23+
}
24+
}
25+
console.log('Nothing match : undefined');
26+
return undefined;
27+
}

0 commit comments

Comments
 (0)