+ 3

What approach can i use to find first repeating element in an array?

Without sorting, and without hashmap.

6th Feb 2020, 4:37 PM
Piyush Srivastava
Piyush Srivastava - avatar
6 Antworten
+ 5
Just iterate over the array and add each value to a Set. The add method of Set returns false if the entry already exists.
6th Feb 2020, 5:39 PM
Tashi N
Tashi N - avatar
+ 3
Lol yeah bro .
6th Feb 2020, 6:32 PM
Piyush Srivastava
Piyush Srivastava - avatar
+ 1
Codder kitten i must be doing it easily by sorting array but it is said that without sorting i have to do this problem.
6th Feb 2020, 6:11 PM
Piyush Srivastava
Piyush Srivastava - avatar
+ 1
Codder kitten is their any other approach rather than hashmap
6th Feb 2020, 6:12 PM
Piyush Srivastava
Piyush Srivastava - avatar
+ 1
The boundation is we should maintain O(n) time complexity without sorting and hashmap so an effective algo needed.
6th Feb 2020, 6:23 PM
Piyush Srivastava
Piyush Srivastava - avatar
+ 1
Piyush Srivastava you should have described all aspects of your problem in the first post to get the right answer in less time 😀.
6th Feb 2020, 6:27 PM
Bahhaⵣ
Bahhaⵣ - avatar