Can Sort Permutation in Given Moves

Amazon interviews coding interview problem: Given a permutation p of length n and q queries moves[i], determine for each query if p can be sorted using exactly moves[i] swaps (each move swaps two distinct indices). Return a binary string of length q with ‘1’ if possible and ‘0’ otherwise. A straightforward interview question on permutations and move counts.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: