Fill Array Zeros with Positive Integers to Satisfy Adjacent |diff| ≤ 1

Asked atZomato
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. 01Ask whether adjacent absolute difference must equal one.
  2. 02Confirm whether existing nonzero values are fixed.
  3. 03Check feasibility between fixed anchors.
  4. 04Construct compatible alternating paths or use DP.
  5. 05Validate positivity and every adjacent pair.

Reference answer

Then expect these follow-ups

  • How do you prove the anchor feasibility condition?

    Tests: correctness reasoning

  • What if the task asks for the number of fills?

    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