Arrays & Strings
3 programs — patterns, complexity, and code
| # | Program Name | Pattern | Time | Space | Key Idea | Level |
|---|---|---|---|---|---|---|
| 1 | twoSum | HashMap | O(n) | O(n) | For each number, check if its complement already exists in a map. | Simple |
| 2 | productExceptSelf | Prefix / Suffix | O(n) | O(1) | Precompute left product array then multiply right product in reverse in-place. | Middle |
| 3 | maxSubarray | Kadane's Algorithm | O(n) | O(1) | Keep a running sum; reset to current element whenever sum drops below it. | Simple |