← J.P. Morgan Interview Insights

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

Intermediate
May 2026

Summary

Two algorithm questions for a software engineer role at J.P. Morgan. Both were pretty classic DSA problems but the ring wrapping detail on the first one tripped me up more than I expected.

Questions Asked (2)

Q1

You have n computers arranged in a circle, each either on or off (represented as 1s and 0s in an array), and an integer k. Find the maximum number of on computers within any k consecutive positions, where the window can wrap around the ring.

Algorithms & Data Structures
Author's notes

The sliding window part I got pretty quickly, but the ring wrapping threw me off for a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that the problem is to find the maximum sum of any k consecutive elements in a circular array. Use a sliding window of size k, compute the initial sum, then slide the window by adding the next element and subtracting the element leaving the window, handling wrap-around with modulo arithmetic. Track the maximum sum seen.

Pro tip: Mention that you can avoid duplicating the array by using modulo indexing, which keeps space complexity O(1) and shows attention to memory efficiency. Also, discuss edge cases like k >= n, where the answer is simply the total number of ones.

1. Clarify the problem

Confirm that the window can wrap around and that k is the window size. Ask about constraints (e.g., n, k) and whether k can be larger than n.

2. Handle edge cases

If k >= n, return the total count of 1s. If k <= 0, return 0. These checks prevent unnecessary computation.

3. Compute initial window sum

Sum the first k elements (indices 0 to k-1) to initialize the current window sum and set it as the maximum.

4. Slide the window circularly

For each starting index i from 1 to n-1, update the sum by adding the element at (i + k - 1) % n and subtracting the element at (i - 1) % n. Update the maximum if the new sum is larger.

5. Return the maximum sum

After iterating through all possible starting positions, return the maximum sum found.

Key Points to Mention

  • Sliding window technique for O(n) time complexity
  • Circular array handling using modulo arithmetic
  • Space complexity O(1) by avoiding array duplication
  • Edge case when k >= n (return total ones)
  • Initial window sum and iterative updates
  • Comparison with brute-force O(n*k) approach to highlight efficiency

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 second is formed by deleting exactly one character from the first, return all zero-based indices in the first string where that deletion could have occurred to produce the second string.

Algorithms & Data Structures
Author's notes

Repeated characters are where this gets annoying.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a two-pointer technique to compare the strings from left to right until a mismatch is found. Then, from that point, check if skipping one character in the first string makes the remainder match the second string. Collect all indices where this condition holds.

Pro tip: Clarify with the interviewer whether the deletion could be at any position, including the end, and discuss the time and space complexity of your solution. Mention edge cases like empty strings or when the second string is empty.

1. Understand the problem

Confirm that the second string is exactly one character shorter and that deleting one character from the first string at some index yields the second string. Consider edge cases such as when the first string is empty or when the deletion is at the beginning or end.

2. Choose an efficient approach

Decide between a brute-force method (try deleting each character and compare) and a more optimal two-pointer or single-pass approach. For large strings, aim for O(n) time complexity.

3. Implement the algorithm

Write code that iterates through the first string, and for each index, checks if removing that character makes the strings equal. Optimize by stopping early when a mismatch is found and only checking the necessary suffix.

4. Test with examples

Run through provided examples and edge cases (e.g., deletion at start, middle, end, multiple valid indices) to verify correctness. Ensure the solution handles all cases.

5. Analyze complexity

State the time and space complexity of your solution. For the optimal approach, it should be O(n) time and O(1) extra space (excluding output).

Key Points to Mention

  • Two-pointer technique to find the first mismatch
  • Checking if the remainder of the first string after the mismatch matches the second string from that point
  • Handling multiple valid deletion indices (e.g., when there are repeated characters)
  • Edge cases: deletion at the beginning, middle, or end; empty strings
  • Time and space complexity analysis (O(n) time, O(1) space)
  • Potential follow-up: what if the second string is formed by deleting multiple characters?

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