Rearrange Array in Zig-Zag Fashion

Asked atF5 Networks
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Clarify desired relation pattern
  2. 02Scan adjacent pairs once
  3. 03Swap only when the current relation fails
  4. 04Alternate expected less-than and greater-than
  5. 05Explain why prior relations remain valid

Reference answer

Then expect these follow-ups

  • Why does one local swap not break the previous relation?

    Tests: correctness reasoning

  • How would you produce the lexicographically smallest valid arrangement?

    Tests: follow-up reasoning

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question