During the contest I used Array of Integer type to avoid TLE, which can occur with array of primitive ints but that led to wrong answer but after I tried with array of primitives and I got AC. Can someone tell me why this is happening?
Submission 1: WA (https://codeforces.net/contest/1592/submission/130698133)
Submission 2: AC (https://codeforces.net/contest/1592/submission/130727745)
You are checking
Integer
objects for equality using!=
, which is comparing the underlying references. This will usually work as desired for numbers in[-128..127]
because these values are singletonized, but will rarely work as desired for any other numbers.