← J.P. Morgan Interview Insights

J.P. Morgan·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Interviewed for a software engineering role at J.P. Morgan and got two algorithmic problems back to back. Nothing too outrageous but the second one took me longer than I'd like to admit.

Questions Asked (2)

Q1

You have a circular array of n computers, each either on (1) or off (0). Find the maximum number of on computers in any contiguous block of k adjacent computers.

Algorithms & Data Structures
Author's notes

Sliding window was the right move but the circular part tripped me up initially.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a sliding window of size k to compute the sum of each window, handling the circular nature by duplicating the array or using modulo indexing. Track the maximum sum encountered, which represents the maximum number of on computers in any contiguous block of k adjacent computers.

Pro tip: Clarify whether k can be greater than n; if so, the answer is simply the total number of on computers. Also, mention that the sliding window approach is optimal for large n, avoiding O(n*k) brute force.

1. Clarify constraints and edge cases

Ask about the range of n and k, and whether k can exceed n. If k >= n, the entire array is the only block, so return the total count of 1s.

2. Choose a strategy for circularity

Decide between duplicating the array (concatenate with itself) or using modulo arithmetic to access elements. Both allow a linear scan without extra space if using modulo.

3. Implement sliding window

Initialize the sum of the first k elements. Then slide the window one step at a time: subtract the element leaving the window and add the new element entering, using modulo for indices.

4. Track and return the maximum

Keep a variable for the maximum sum seen. After each slide, update it if the current sum is larger. Return the maximum after checking all n windows.

5. Analyze complexity

State that the time complexity is O(n) and space complexity is O(1) if using modulo, or O(n) if duplicating the array. This is optimal.

Key Points to Mention

  • Sliding window technique for fixed-size windows
  • Handling circular arrays via modulo indexing or array duplication
  • Time complexity O(n) and space complexity O(1) with modulo
  • Edge case: k >= n returns total count of 1s
  • Avoiding brute force O(n*k) by reusing previous window sum
  • Potential follow-up: what if k is not fixed? (Then it's a different problem)

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

Q2

Given two strings where the first is exactly one character longer than the second, and the second can be formed by removing exactly one character from the first, return all indices in the first string where removing that character produces the second string.

Algorithms & Data Structures
Author's notes

Two pointer approach.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then propose an efficient two-pointer algorithm that scans both strings in a single pass to identify all valid removal indices. Discuss time and space complexity, and consider whether multiple valid indices are possible.

Pro tip: Mention that in the worst case (e.g., all characters identical), there can be O(n) valid indices, so the output size itself is O(n). This shows you think about output-sensitive complexity and practical constraints.

1. Clarify the problem

Confirm that the first string is exactly one character longer, that the second can be formed by removing exactly one character, and that we need to return all such indices. Ask about input size, character set, and whether multiple valid indices are possible.

2. Identify edge cases

Consider cases like empty strings, strings with all identical characters, and the position of the removed character at the beginning or end. These help validate the solution.

3. Design an efficient algorithm

Use a two-pointer approach: iterate through both strings, and when characters mismatch, record the current index in the first string as a candidate. Then check if skipping that character allows the rest to match. Alternatively, precompute prefix and suffix matches to find all valid indices in O(n) time.

4. Analyze complexity

State that the algorithm runs in O(n) time and O(1) extra space (excluding output), where n is the length of the first string. If using prefix/suffix arrays, space is O(n).

5. Test with examples

Walk through a few examples, including edge cases, to demonstrate correctness. For instance, s1='abc', s2='ac' returns [1]; s1='aaa', s2='aa' returns [0,1,2].

Key Points to Mention

  • Two-pointer technique for linear scan
  • Handling multiple valid indices (e.g., all identical characters)
  • Time complexity O(n) and space complexity O(1) or O(n) depending on approach
  • Edge cases: removal at start/end, empty strings, all characters same
  • Output-sensitive complexity: number of valid indices can be up to n
  • Correctness proof: invariant that prefix and suffix match after skipping candidate index

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