Array

Asked atJ.P. MorganMicrosoftSwiggy
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 for the exact array task and constraints.
  2. 02Determine whether order may change and whether mutation is allowed.
  3. 03Choose scan, hash map, sorting, prefix, or two-pointer technique.
  4. 04State the loop invariant before coding.
  5. 05Test empty, singleton, duplicate, and boundary values.

Reference answer

Then expect these follow-ups

  • What information determines whether sorting is allowed?

    Tests: follow-up reasoning

  • Which invariant would you state for an in-place filter?

    Tests: constraint adaptation

Hiring now

Swiggy has 152 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.
  • Content Lead

    Mumbai, MH, India

  • Sales Manager I

    Kolhapur, MH, India

  • Assistant Manager- Finance

    Bengaluru, KA, India

Or practice this question first

Next question