Here's how I would go about solving this one :- 1) create an array of size (n) and initialise every index with value 0 ( this array will represent the frequency of the elements occured in the input array ) 2) while traversing the input digits, increment the frequency at index accordingly. 3) traverse the entire frequency array and see if all the numbers occured atleast 2 times or not
Roy Kapoor the idea is to simply traverse all the integers from 1 to N and check if the frequency of the number is present atleast twice in the input array or not. here's a brute force solution :- For every element in set [1,N] loop over the entire input array to see if that perticular number is present at least twice or not. Although the solution I gave you before is much optimised that this (in terms of time complexity) but if you find that comparatively complicated then try going for brute force first.
Can you please help me in code..