Find the Largest Submatrix with all 1s

Asked atDoorDash
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 whether columns may be rearranged.
  2. 02Accumulate consecutive-one heights per column.
  3. 03For fixed columns, solve largest rectangle in histogram.
  4. 04For rearrangeable columns, sort heights each row.
  5. 05Track maximal area and test zero resets.

Reference answer

Then expect these follow-ups

  • Why does a monotonic stack find every maximal rectangle?

    Tests: correctness reasoning

  • What changes if columns can be permuted?

    Tests: constraint adaptation

Hiring now

DoorDash has 342 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.
  • Senior Software Engineering, Backend (All Teams) - Vaga para mulheres

    São Paulo, Brazil

  • Senior Software Engineering, Backend (All Teams) - Vaga exclusiva para PCD

    São Paulo, Brazil

  • Senior Software Engineering, Backend

    Hyderabad, India

Or practice this question first

Next question