Find whether the array can be sorted in exactly N swaps
Anonymous User
365

Given an array of N integers, return true or false based on if the array can be sorted in exactly N swaps if you are allowed to swap only relatively odd indexed elements.

So if you select index x, where 0 <= x <= N, then you can swap arr[x] with only

x-1, x-3, ... , x - i where x - i >= 0, or
x + 1, x + 3, ... , x + i where x + i < N

Comments (0)