Skip to content
BytePatterns

Arrays

Pointers, windows and in-place tricks, drawn out step by step.

Arrays progress0 / 14
  1. Array BasicsOne block of memory, instant access to any slot.4m
  2. Two PointersTwo indexes closing in beat one loop nesting another.5m
  3. Sliding WindowReuse the last answer instead of recomputing it.5m
  4. Prefix SumsPay once up front, answer range queries instantly.5m
  5. In-Place ReversalFlip an array with one temp variable, not a copy.4m
  6. Move ZeroesPush the junk to the back without losing the order.5m
  7. Container With Most WaterThe shorter wall decides. So move the shorter wall.6m
  8. Kadane's AlgorithmDrop the past the moment it starts costing you.6m
  9. Cyclic SortWhen values are 1..n, every value already knows its index.5m
  10. Merge Sorted ArraysFill from the back and you never overwrite unread data.5m
  11. Dutch National FlagThree values, three regions, one pass.5m
  12. Product Except SelfTwo sweeps beat one division.5m
  13. Rotate an ArrayThree reversals move every element home.4m
  14. Majority ElementCancel the votes in pairs and the majority survives.5m

Quiz yourself: 3 questions from this module

1 / 3

Why is reading arr[i] O(1)?