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

Hiring now

Zomato is hiring 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.
  • Software Engineer – Back End

    Gurugram, HR, India

Or practice this question first

Next question