This is one of basic searching algorithm question.
In this post, we’ll look into different approaches of checking whether array has duplicate elements or not. In addition to this, we’ll also see how to findall duplicate elements from array in one pass.
Approach 1 Brute-Force approach
In this method, for each input elements check whether there is any element with the same value. This we can solve with two loops.
Time Complexity : O(n^2) for nested loops, Space Complexity : O(1)