Loading...
Loading...
Loading...
A designer makes bead necklaces, coding each bead colour as a number. A necklace looks the same from both ends when its array reads the same forwards and backwards (a palindrome). Check a necklace.
YES if the array is a palindrome, otherwise NO.Example 1
Input
5 3 1 4 1 3
Output
YES
3 1 4 1 3 backwards is the same.
Example 2
Input
4 2 5 5 3
Output
NO
The ends, 2 and 3, already differ.
Try the problem first. Open one hint at a time.
Compare a[i] with its mirror a[n - 1 - i].
Only the first half needs checking; stop at the first mismatch.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor