Software Interviewing Reference

Kip Landergren

Contents

sample response guide

  1. restate the problem
    • confirm understanding in your own words
    • clarify inputs, outputs, and edge cases
    • ask about constraints (input size, time/space expectations)
  2. establish complexity target
    • estimate the feasible time complexity based on constraints
    • state any quick sanity check: e.g. “n is 10⁵, so o(n²) is too slow”
  3. outline initial ideas
    • start with brute force to define the baseline
    • identify performance bottlenecks
    • mention candidate patterns (two-pointer, hashmap, bfs, etc.)
  4. select and justify approach
    • choose the data structure or algorithm that meets the target
    • explain why it fits: e.g., “sorted input → two-pointer,”
  5. describe plan before coding
    • specify input → process → output flow
    • walk through one example by hand to confirm logic
  6. implement cleanly
    • code incrementally, testing small parts as you go
    • use clear variable names and minimal state mutations
  7. test and verify
    • run through sample and edge cases verbally or in code
    • check for off-by-one errors, empty inputs, duplicates
  8. analyze complexity
    • restate final time and space complexity
    • note tradeoffs and possible optimizations
  9. reflect and optimize
    • mention potential improvements or alternate approaches
    • justify current choice if optimal
  10. summarize outcome
    • restate problem, solution idea, and complexity in one sentence
    • confirm correctness and efficiency confidently

problem 1

Leetcode 1672 - Richest Customer Wealth

You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank.

Return the wealth that the richest customer has.

A customer's wealth is the total amount of money they have in all their bank accounts.

The richest customer is the one with the maximum wealth.

example 1

Input:

accounts = [[1,2,3],[3,2,1]]

Output:

6

Explanation:

example 2

Input:

accounts = [[1,5],[7,3],[3,5]]

Output:

10

Explanation:

The 2nd customer is the richest with a wealth of 10.

example 3

Input:

accounts = [[2,8,7],[7,1,3],[1,9,5]]

Output:

17

constraints

m == accounts.length
n == accounts[i].length
1 <= m, n <= 50
1 <= accounts[i][j] <= 100

Problem 2

Longest Consecutive Sequence

Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.

You must write an algorithm that runs in O(n) time.

example 1

Input:

nums = [100,4,200,1,3,2]

Output:

4

Explanation:

The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.

example 2

Input:

nums = [0,3,7,2,5,8,4,6,0,1]

Output:

9

example 3

Input:

nums = [1,0,1,2]

Output:

3

constraints

0 <= nums.length <= 10^5
-10^9 <= nums[i] <= 10^9

problem 3

Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

Implement the MinStack class:

You must implement a solution with O(1) time complexity for each function.

example 1

Input:

["MinStack","push","push","push","getMin","pop","top","getMin"]
[[],[-2],[0],[-3],[],[],[],[]]

Output:

[null,null,null,null,-3,null,0,-2]

Explanation:

MinStack minStack = new MinStack();
minStack.push(-2);
minStack.push(0);
minStack.push(-3);
minStack.getMin(); // return -3
minStack.pop();
minStack.top(); // return 0
minStack.getMin(); // return -2

constraints

-2^31 <= val <= 2^31 - 1
Methods pop, top, and getMin operations will always be called on non-empty stacks.
At most 3 * 10^4 calls will be made to push, pop, top, and getMin.

problem 4

Daily Temperatures

Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.

example 1

Input:

temperatures = [73,74,75,71,69,72,76,73]

Output:

[1,1,4,2,1,1,0,0]

example 2

Input:

temperatures = [30,40,50,60]

Output:

[1,1,1,0]

example 3

Input:

temperatures = [30,60,90]

Output:

[1,1,0]

contraints

1 <= temperatures.length <= 105
30 <= temperatures[i] <= 100