← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026Remote

Summary

Amazon SWE interview with two algorithmic problems back to back. Both were more math-flavored than I expected, especially the first one. Not your typical LeetCode grind session.

Questions Asked (2)

Q1

You're given a positive-integer array A of length n. You can freely choose any integer array B of the same length. Define C[i] = B[i] mod A[i]. What is the maximum number of distinct values C can contain, and how do you compute that maximum efficiently? Give time and space complexities.

Algorithms & Data Structures
Author's notes

This one took me a minute to even parse what they were asking.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, recognize that for each index i, C[i] can be any integer from 0 to A[i]-1, so the maximum distinct values is the size of the union of these ranges. Since the ranges are contiguous from 0, the union is simply [0, max(A)-1], so the answer is max(A). Then, justify why this is achievable by setting B[i] = i for i < max(A) and B[i] = 0 for the rest, ensuring all values 0..max(A)-1 appear.

Pro tip: Mention that the problem reduces to finding the maximum element, which is O(n) time and O(1) space, and emphasize that no sorting or complex data structures are needed. This shows you can simplify problems to their core.

1. Understand the range of each C[i]

For each i, C[i] = B[i] mod A[i] can be any integer from 0 to A[i]-1 because B[i] can be chosen freely. So the set of possible values for index i is exactly {0, 1, ..., A[i]-1}.

2. Determine the union of all possible values

The overall set of possible distinct values is the union of these ranges. Since each range starts at 0, the union is simply {0, 1, ..., max(A)-1}, which has size max(A).

3. Show achievability

To achieve all values from 0 to max(A)-1, assign B[i] = i for indices where i < max(A), and B[i] = 0 for the rest. This ensures each value 0..max(A)-1 appears as C[i] for some i.

4. Compute the maximum efficiently

The maximum number of distinct values is simply the maximum element in A. Find it by a single pass through the array, which takes O(n) time and O(1) extra space.

5. State complexities and edge cases

Time complexity: O(n). Space complexity: O(1). Handle edge cases: if n=0 (though not possible for positive length), or if all elements are 1, then max=1 and only value 0 is possible.

Key Points to Mention

  • The range of C[i] is exactly [0, A[i]-1] because B[i] can be any integer.
  • The union of ranges [0, A[i]-1] is [0, max(A)-1].
  • The maximum number of distinct values is max(A).
  • Achievability: assign B[i] = i for i < max(A) and B[i] = 0 otherwise.
  • Time complexity: O(n) to find the maximum; space complexity: O(1).
  • No need for sorting or additional data structures; the problem reduces to finding the maximum element.

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

Q2

Given two lowercase strings s and t, you can pick one letter in each string (independently) and delete any number of occurrences of that letter. After doing this, can s and t become anagrams of each other? Design an algorithm and analyze its complexity.

Algorithms & Data Structures
Author's notes

Felt more approachable than the first problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem: you can choose one letter from each string and delete any number of its occurrences. The goal is to determine if the resulting strings can be anagrams. The key insight is that after deletion, the only letters that can differ in frequency are the two chosen letters; all other letters must have identical frequencies in both strings. So, check if the strings differ in at most two letters, and if so, whether the frequency differences can be resolved by deleting occurrences of the chosen letters.

Pro tip: Mention that the chosen letters can be the same or different, and that you can delete zero occurrences. This shows attention to edge cases and can simplify the solution.

1. Clarify the operation

Restate the problem: pick one letter from s and one from t (possibly the same), and delete any number of occurrences of those letters from their respective strings. The resulting strings must be anagrams.

2. Identify necessary conditions

For the strings to become anagrams, all letters except the two chosen ones must have equal frequencies in s and t. Thus, the set of letters with differing frequencies must be a subset of the two chosen letters.

3. Check frequency differences

Compute frequency arrays for s and t. Find all letters where frequencies differ. If more than two letters differ, return false. If zero differ, return true (already anagrams). If one or two differ, proceed.

4. Verify if differences can be resolved

If exactly one letter differs, it must be chosen from both strings (or one string and the other chosen letter has zero difference). If two letters differ, say a and b, then the excess of a in one string must equal the deficit of b in the other, and vice versa, so that deleting occurrences of a and b can balance frequencies.

5. Analyze complexity

The algorithm runs in O(n + m) time and O(1) space (since alphabet size is 26), which is optimal.

Key Points to Mention

  • Frequency counting using arrays or hash maps
  • The condition that at most two letters can have differing frequencies
  • The ability to choose the same letter from both strings
  • Edge cases: strings already anagrams, strings with no common letters, empty strings
  • Time complexity O(n + m) and space complexity O(1) (or O(26))
  • Proof of correctness: why the condition is necessary and sufficient

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