Timed Mock Interview: Easy and Medium Problems
Solve three problems under a 45-minute timer, verbalise your thought process as you would in a real interview, and review optimal solutions afterward.
How to Use This Mock Interview
This lesson simulates a real coding interview session. For each problem, you should: (1) read it once, (2) identify the pattern within 60 seconds, (3) state your approach and complexity, (4) write the solution, and (5) test with examples. Set a timer. An easy problem should take 10-15 minutes; a medium problem 20-25 minutes.
Do not look ahead at the solution — it defeats the purpose. If you are stuck after 5 minutes, re-read the problem statement and look for the signal word that reveals the pattern (sorted? minimum? all combinations? subarray?). The ability to self-unstick is as important as the ability to solve quickly.
# Mock interview timer simulation
import time
class InterviewTimer:
def __init__(self, total_minutes):
self.total = total_minutes * 60
self.start = None
def begin(self, problem_name):
self.start = time.time()
print(f'TIMER STARTED: {problem_name}')
print(f'You have {self.total//60} minutes. Go!')
def checkpoint(self, label):
if self.start:
elapsed = time.time() - self.start
remaining = self.total - elapsed
print(f'[{label}] Elapsed: {elapsed:.0f}s, Remaining: {remaining:.0f}s')
# Usage in real practice:
timer = InterviewTimer(15) # 15-minute easy problem
timer.begin('Two Sum')
time.sleep(1)
timer.checkpoint('Identified pattern')Easy Problem 1: Valid Parentheses
Problem: Given a string containing only '(', ')', '{', '}', '[', ']', determine if the input string is valid. A string is valid if every open bracket is closed by the same type of bracket in the correct order.
Signal: Matching pairs, ordering matters, most recent open bracket must close first → Stack. Push open brackets; pop and verify on close brackets. If the stack is empty when we try to pop, or has leftover items at the end, the string is invalid. Time O(n), Space O(n).
def is_valid(s):
stack = []
matching = {')': '(', '}': '{', ']': '['}
for char in s:
if char in '({[':
stack.append(char)
else:
if not stack or stack[-1] != matching[char]:
return False
stack.pop()
return len(stack) == 0
# Test cases
test_cases = [
('()', True),
('()[]{}' , True),
('(]', False),
('([)]', False),
('{[]}', True),
('', True), # empty string is valid
('(((', False), # unmatched opens
(')]', False), # close without open
]
for s, expected in test_cases:
result = is_valid(s)
status = 'PASS' if result == expected else 'FAIL'
print(f'{status}: is_valid({repr(s)}) = {result} (expected {expected})')All lessons in this course
- Pattern Recognition Cheat Sheet
- Timed Mock Interview: Easy and Medium Problems
- Handling Edge Cases and Interviewee Communication
- Hard Problem Walkthroughs: Word Ladder II and Alien Dictionary