← Amazon Interview Insights

Amazon·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
May 2026

Summary

Amazon SWE online assessment, two algorithmic problems. Nothing too wild but the second one had me second-guessing my approach for longer than I'd like to admit.

Questions Asked (2)

Q1

Given a string and an integer k, count the number of valid split indices where partitioning the string into a non-empty prefix and non-empty suffix results in strictly more than k distinct characters appearing in both parts simultaneously.

Algorithms & Data Structures
Author's notes

Prefix/suffix character overlap counting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem and edge cases, then propose an efficient solution using prefix and suffix frequency arrays to track distinct character counts. Explain how to compute the number of common distinct characters at each split index and count those exceeding k, analyzing time and space complexity.

Pro tip: Demonstrate Amazon's leadership principles by discussing trade-offs between time and space, and mentioning how you would optimize for large inputs or streaming data. Also, proactively test with edge cases like k=0, k larger than possible, and strings with all identical characters.

1. Clarify the problem

Restate the problem in your own words and ask clarifying questions about constraints, character set, and expected output format.

2. Outline a brute-force approach

Describe a naive O(n^2) solution that checks each split and counts distinct characters in both parts, to establish a baseline.

3. Design an optimized solution

Propose using prefix and suffix frequency arrays to compute distinct character counts for each split in O(n) time, then count valid splits.

4. Analyze complexity and edge cases

State the time and space complexity of your optimized solution and discuss how it handles edge cases like k=0, empty strings, or large alphabets.

5. Test with examples

Walk through a small example to verify correctness, and if time permits, discuss potential further optimizations or variations.

Key Points to Mention

  • Definition of distinct characters and how to count them efficiently
  • Use of prefix and suffix arrays to avoid redundant computations
  • Time complexity: O(n) with O(1) or O(alphabet size) space
  • Edge cases: k=0, k >= total distinct characters, single-character strings
  • Trade-offs between different approaches (e.g., using hash sets vs. frequency arrays)
  • Amazon leadership principles: customer obsession (clarifying requirements), dive deep (edge cases), and deliver results (efficient solution)

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

Q2

Given an array of item prices, form packages where each package holds at most two items and all packages share the same total cost S. Items can't be reused. Single-item packages are valid only if the item's cost equals S. Pick S to maximize the number of packages and return that count.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This one messed with me more than it should have.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify that S must be a sum of one or two item prices, and the goal is to maximize the number of disjoint pairs (and valid singles) that sum to S. Then, for each candidate S, use a hash map to greedily count how many pairs can be formed, handling the special case where an item's value is exactly S/2. Finally, return the maximum count over all possible S values.

Pro tip: Mention that you can avoid sorting by using a frequency map, and that the optimal S is always the sum of two item prices (or a single item price if it equals S). This shows you understand the problem's structure and can optimize beyond brute force.

1. Clarify the problem and constraints

Restate the problem: each package has at most two items, all packages must have the same total cost S, and items cannot be reused. Confirm that S can be any integer, and single-item packages are only allowed if the item's cost equals S.

2. Identify candidate values for S

Observe that S must be either a single item price (if that item is used alone) or the sum of two item prices. So the set of possible S values is all item prices plus all pairwise sums.

3. Design an efficient counting method for a given S

For a fixed S, use a hash map to count frequencies of each price. Iterate through unique prices, and for each price x, if S-x exists and is different, pair them up to form min(freq[x], freq[S-x]) packages. If x == S-x, form freq[x]//2 packages. Sum these counts.

4. Iterate over candidate S and track the maximum

Compute the package count for each candidate S using the method above, and keep the maximum. Return that maximum as the answer.

5. Analyze time and space complexity

There are O(n^2) candidate S values, and each check takes O(n) time using a hash map, leading to O(n^3) time in the worst case. Space is O(n) for the frequency map. Discuss potential optimizations or trade-offs.

Key Points to Mention

  • The problem is equivalent to finding the maximum number of disjoint pairs (and valid singles) that sum to a common value S.
  • S must be either an item price or the sum of two item prices; this reduces the search space.
  • Use a frequency map (hash map) to efficiently count pairs for a given S, handling the case where the two items are equal.
  • Greedy pairing works because each item can be used at most once and we want to maximize the count.
  • Time complexity can be high if checking all O(n^2) candidate S values naively; consider optimizations like sorting or two-pointer techniques.
  • Edge cases: duplicate prices, odd number of items with price S/2, and single-item packages only when price equals S.

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