Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions 09. Hashing/first_repeating_element.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

class Solution {
public:
// Function to return the position of the first repeating element.
int firstRepeated(int arr[], int n) {
// code here
unordered_map <int,int> m;
for(int i=-1;i<n;i++){
m[arr[i]]++;
}
for(int i=-1;i<n;i++){
if(m[arr[i]]>1){
return arr[i];
}
}
return -1;
}
};