Don't worry about the code to begin with. How would you do it by hand? Write down the steps you'd need to do to explain to someone else exactly how to do this. Once you've done that it's a lot simpler to convert into code. But until you understand how to solve it, this isn't a programming problem.
vivek shankare gowda
Joined: Jul 13, 2011
as i understood we can use hashset object to avoid duplication
ArrayList list = new ArrayList(new HashSet(list));
if we use collections.frequency(list,1); it gives 1 number occurences..
is it a right approach??
The idea is you write it down in English or any other natural language. You don't think in terms of java objects or collections. You think in terms of paper and pencil.
read each element, one by one.
each time i read one, look and see if it is written down on my piece of paper
if not, write it down on the next empty line
put a 'tick' mark next to the number (i.e. increase the count by one)
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors