Loading section...
Space Complexity Basics
Space complexity measures how much memory your algorithm uses relative to input size. Sometimes you can trade space for time, using more memory to run faster. O(1) Space Uses a fixed amount of memory regardless of input size. Only a few variables, no new collections. O(n) Space Memory grows with input size. Creating new lists, building results. Allocating memory proportional to input size when only a boolean answer is needed is a common beginner mistake. Early return reduces both time complexity (stops at the first positive) and space complexity (no extra list).