Explain time and space complexity.
01
01
Understand the problem
complexitybig-o
02
02
Attempt it yourself
Sketch your approach before reading the solution — that's what interviews test.
Stuck? AI Nudge Available
Get a conceptual hint to guide your logic without spoiling the final implementation.
03
03
Study the solution
The solution is waiting
Give it an honest attempt first — then compare your thinking with the full walkthrough.
04
04
Read the code
Constant vs linear vs quadratic
Run Playgrounddef constant(nums): # O(1) - one access, size-independent
return nums[0] if nums else None
def linear(nums, target): # O(n) - touches each element once
for x in nums:
if x == target:
return True
return False
def quadratic(nums): # O(n^2) - every pair
pairs = []
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
pairs.append((nums[i], nums[j]))
return pairs
# --- demo ---
print(constant([10, 20, 30])) # 10
print(linear([10, 20, 30], 20)) # True
print(quadratic([1, 2, 3])) # [(1, 2), (1, 3), (2, 3)]05
05
Join the discussion
Discussion (0)
Sign in to join the discussion.
No responses yet. Be the first to share what you think.