java program find duplicate value by negation solution error java.lang.ArrayIndexOutOfBoundsException: -3 [duplicate]

Either take array element 0 to 4

Or change your logic inside for loop : decrease 1 inside array index
eg. a[a[I] - 1] = ...like this

Leave a Comment