Mock Week 1 — Easy + Medium Mix with Communication Focus

Sanjeev SharmaSanjeev Sharma
2 min read

Advertisement

Week 1 Goals

  • Solve both problems correctly
  • Narrate your thinking continuously
  • Finish each in under 45 minutes
  • State complexity at the end

Session A — Arrays

Problem 1 (Easy): Best Time to Buy and Sell Stock

Think-aloud script:

"So I need to find max profit from one buy and one sell.
 I can't sell before buying, so I track min price seen so far.
 For each price: profit = price - min_so_far; update min.
 That's O(n) time, O(1) space."
def maxProfit(prices):
    min_price = float('inf')
    max_profit = 0
    for p in prices:
        min_price = min(min_price, p)
        max_profit = max(max_profit, p - min_price)
    return max_profit

Problem 2 (Medium): Product of Array Except Self

Think-aloud script:

"No division allowed. I can do prefix products from left,
 suffix products from right, multiply them.
 Left pass: output[i] = product of all left of i.
 Right pass: multiply by running right product.
 O(n) time, O(1) extra space (output array doesn't count)."
def productExceptSelf(nums):
    n = len(nums)
    res = [1] * n
    left = 1
    for i in range(n):
        res[i] = left
        left *= nums[i]
    right = 1
    for i in range(n-1, -1, -1):
        res[i] *= right
        right *= nums[i]
    return res

Session B — Trees

Problem 1 (Easy): Maximum Depth of Binary Tree

def maxDepth(root):
    if not root: return 0
    return 1 + max(maxDepth(root.left), maxDepth(root.right))

Problem 2 (Medium): Validate Binary Search Tree

def isValidBST(root):
    def validate(node, lo, hi):
        if not node: return True
        if not (lo < node.val < hi): return False
        return validate(node.left, lo, node.val) and validate(node.right, node.val, hi)
    return validate(root, float('-inf'), float('inf'))

Communication Checklist

Before coding, always say:

  • "Let me restate the problem..."
  • "Edge cases I'm considering: empty input, single element, negatives..."
  • "My approach is X because Y..."
  • "Time complexity will be O(...) because..."

During coding:

  • Name variables clearly (left_max not lm)
  • Say what each block does: "This for loop builds the prefix array..."

After coding:

  • "Let me trace through the example: input=[1,3,-1], k=3..."
  • "Edge case: what if the array is empty? We return 0 here..."

Advertisement

Sanjeev Sharma

Written by

Sanjeev Sharma

Full Stack Engineer · E-mopro