I was asked a question in an interview the other day:
You have an array list of numbers from 1 to 100, the problem is that one number is missing. How would you find that number?
This is a mock of the question. The code seems to work.
Could you give me some feedback?
private int count;
public void find() {
//prep for question
List<Integer> ints = new ArrayList();
for (int i = 0; i < 100; i++) {
ints.add(i);
}
ints.remove(67);
//find the missing number
for (Integer i : ints) {
if (i != count) {
System.out.println(count);
count++;
}
count++;
}
}
Output = 67