Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Largest Rectangle in Histogram

Lu Dang
September 25, 2016

Largest Rectangle in Histogram

Lu Dang

September 25, 2016
Tweet

Other Decks in Technology

Transcript

  1. 2 1 5 6 2 3 0 positions heights 0

    2 maxVal = 0 i == 0
  2. 2 1 5 6 2 3 0 positions heights 0

    2 maxVal = 0 i == 1
  3. 2 1 5 6 2 3 0 positions heights i

    == 1 maxVal = max(0, (i - 0) * 2) = 2 2
  4. 2 1 5 6 2 3 0 positions heights 0

    1 i == 1 maxVal = max(0, (i - 0) * 2) = 2
  5. 2 1 5 6 2 3 0 positions heights 0

    1 maxVal = 2 i == 2 2 5
  6. 2 1 5 6 2 3 0 positions heights 0

    1 maxVal = 2 i == 3 2 5 3 6
  7. 2 1 5 6 2 3 0 positions heights 0

    1 maxVal = 2 i == 4 2 5 3 6
  8. 2 1 5 6 2 3 0 positions heights 0

    1 maxVal = max(2, (i - 3) * 6) = 6 i == 4 2 5 6
  9. 2 1 5 6 2 3 0 positions heights 0

    1 maxVal = max(6, (i - 2) * 5) = 10 i == 4 10
  10. 2 1 5 6 2 3 0 positions heights 0

    1 maxVal = 10 i == 4 2 2
  11. 2 1 5 6 2 3 0 positions heights 0

    1 maxVal = 10 i == 5 2 2 5 3
  12. 2 1 5 6 2 3 0 positions heights 0

    1 maxVal = 10 i == 6 2 2 5 3
  13. 2 1 5 6 2 3 0 positions heights 0

    1 maxVal = max(10, (i - 5) * 3) = 10 i == 6 2 2 3
  14. 2 1 5 6 2 3 0 positions heights 0

    1 maxVal = max(10, (i - 2) * 2) = 10 i == 6 8
  15. 2 1 5 6 2 3 0 positions heights maxVal

    = max(10, (i - 0) * 1) = 10 i == 6 6