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

Hiring now

F5 Networks has 272 open roles right now

landed applies to roles like these for you, on each company’s own site, with answers written for the role.

Get 5x interviews10 free auto-applies. No card.
  • Principal Software Development Engineer

    Hyderabad (SEZ)

  • Sr Software Engineer

    Hyderabad (SEZ)

  • Software Engineer III

    Hyderabad (SEZ)

Or practice this question first

Next question