The following is a question from a Cracking coding interview:
You have an array with all numbers from 1 to N, where N is no more than 32000. The array can have duplicate entries, and you don't know what N is. With only 4 KB of memory, how would you print all duplicate elements in an array?
Method signature
public static void checkDuplicates(int[] array)
The solution then explains how you can use bit-bit to solve this problem, representing each integer as a bit. My confusion, when we run this method, will it not load the entire array in memory to go through it? Now, if the size arrayhas a size, for example, 1 billion (many duplicate elements) will not skip this program, since it loads the entire array in memory, and do we have 32 * 2^10bits in memory ?
source
share