← Microsoft Interview Insights

Microsoft·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Microsoft SWE interview with two coding questions back to back. One tree problem, one DP string problem. Nothing too wild but the combo felt like a lot to get through cleanly in one session.

Questions Asked (2)

Q1

Given a binary tree, return its node values level by level from bottom to top, where each level lists nodes left to right but the levels themselves are ordered deepest first.

Algorithms & Data Structures
Author's notes

BFS then reverse the result.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a level-order traversal (BFS) with a queue to collect nodes level by level, then reverse the list of levels to get bottom-to-top order. Alternatively, use DFS to record each node's depth and then reverse the levels. Clearly state the time and space complexity and discuss trade-offs.

Pro tip: Mention that you can avoid reversing the entire result by using a deque and appending each level to the front, but note that this still requires O(n) extra space. Also, clarify that 'bottom to top' means the deepest level first, and ensure your traversal maintains left-to-right order within each level.

1. Clarify the problem

Confirm that the output should be a list of lists, where each inner list contains node values from left to right at a given depth, and the outer list is ordered from the deepest level to the root. Ask about edge cases like an empty tree.

2. Choose an approach

Decide between BFS with a queue and DFS with depth tracking. BFS naturally processes level by level; DFS can also work by storing nodes in a map keyed by depth. Mention that both are valid and discuss trade-offs.

3. Implement the traversal

For BFS: use a queue, process each level by recording its size, dequeue nodes, collect their values, and enqueue their children. For DFS: recursively traverse, passing depth, and append node values to a list for that depth.

4. Reverse the levels

After collecting levels in top-to-bottom order, reverse the list of levels to achieve bottom-to-top order. Alternatively, use a deque and append each level to the front during traversal.

5. Analyze complexity and test

State that time complexity is O(n) and space complexity is O(n) for the queue or recursion stack plus the output. Walk through a small example to verify correctness, including edge cases like a single node or skewed tree.

Key Points to Mention

  • Level-order traversal (BFS) using a queue
  • DFS with depth tracking as an alternative
  • Reversing the list of levels or using a deque to prepend
  • Time complexity O(n) and space complexity O(n)
  • Handling edge cases: empty tree, single node, skewed tree
  • Maintaining left-to-right order within each level

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Given a string, find the length of its longest palindromic subsequence.

Algorithms & Data Structures
Author's notes

Classic DP but I blanked on the recurrence for a second.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and discussing a brute-force approach, then optimize using dynamic programming. Explain the DP recurrence based on comparing characters at both ends and derive the solution for the longest palindromic subsequence. Analyze time and space complexity, and mention potential optimizations.

Pro tip: Relate the problem to the Longest Common Subsequence (LCS) between the string and its reverse, which provides an alternative DP formulation and shows deeper insight. Also, be prepared to discuss space optimization from O(n^2) to O(n) if asked.

1. Clarify and Define

Confirm that a subsequence does not require contiguous characters and that we seek the maximum length. Discuss edge cases like empty string or single character.

2. Brute Force and Identify Overlapping Subproblems

Mention that a naive recursive approach would explore all subsequences, leading to exponential time. Highlight that the problem exhibits optimal substructure and overlapping subproblems, making DP suitable.

3. Formulate DP Recurrence

Define dp[i][j] as the length of the longest palindromic subsequence in substring s[i..j]. If s[i] == s[j], dp[i][j] = dp[i+1][j-1] + 2; else dp[i][j] = max(dp[i+1][j], dp[i][j-1]). Base case: dp[i][i] = 1.

4. Implement and Optimize

Fill the DP table in increasing order of substring length. Discuss time complexity O(n^2) and space complexity O(n^2), and mention that space can be reduced to O(n) by using two rows.

5. Test and Validate

Walk through a small example (e.g., 'bbbab' returns 4) to verify the recurrence. Discuss how to handle large inputs and potential follow-up questions.

Key Points to Mention

  • Definition of subsequence vs substring
  • Dynamic programming state and recurrence
  • Time and space complexity analysis
  • Space optimization using rolling arrays
  • Alternative approach via LCS with reversed string
  • Edge cases: empty string, single character, all same characters

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.