Given an array of n elements which contains index elements from 0 to n-1, with any of these numbers appearing any number of times. Find these repeating numbers in O(n) and using only constant memory space.

For example, let n be 7 and array be {1, 2, 3, 1, 3, 6, 6}, the answer should be 1, 3 and 6.

Answer- so basically the in the loop take the element and put a minus sign then when you see the same number it will not be greater than 0, it will be a negative, so it means you encountered the number, so print it , thats the duplicate

for (i = 0; i < size; i++)

{

if (arr[Math.abs(arr[i])] >= 0)

arr[Math.abs(arr[i])] = -arr[Math.abs(arr[i])];

else

System.out.print(Math.abs(arr[i]) + ” “);

}

==========================================

using collections

```
public class DuplicateWordSearcher {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
String text = "a r b k c d se f g a d f s s f d s ft gh f ws w f v x s g h d h j j k f sd j e wed a d f";
List<String> list = Arrays.asList(text.split(" "));
Set<String> uniqueWords = new HashSet<String>(list);
for (String word : uniqueWords) {
System.out.println(word + ": " + Collections.frequency(list, word));
}
}
```