Hi,
First of all. Great resource for getting hands on programming interviews. We can improve the test cases in epi-judge-java for the same. I was able to pass all the tests with insufficient clauses in while loop.
Given in the book is:
while (0 < A.get(i) && A.get(i) <= A.size() && !A.get(A.get(i) - 1).equals(A.get(i))
I was able to pass the tests with
while (0 < A.get(i) && !A.get(A.get(i) - 1).equals(A.get(i))
I realize A.get(i) <= A.size() is an important clause for some use-cases.
My two cents.