← Amazon Interview Insights

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

Intermediate
Apr 2026

Summary

Amazon SWE online assessment with two algorithmic problems back to back. Pretty standard OA format, nothing too surprising, but the second problem had more moving parts than I expected.

Questions Asked (2)

Q1

Given a string, count the number of ways to split it into exactly two non-empty contiguous parts (a prefix and a suffix) such that the count of distinct characters shared by both parts exceeds k.

Algorithms & Data Structures
Author's notes

Spent way too long overthinking the data structure here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then propose an efficient solution using prefix and suffix frequency arrays to track distinct characters. Explain how to compute the intersection count for each split in O(1) after O(n) preprocessing, and analyze time and space complexity.

Pro tip: Mention that you can optimize space by using bitmasks if the character set is small (e.g., lowercase English letters), and discuss trade-offs between different approaches to show depth.

1. Clarify the problem

Confirm the definition of 'distinct characters shared by both parts' and ask about constraints (e.g., string length, character set).

2. Brute force approach

Describe a naive O(n^2) solution: for each split, compute the distinct characters in prefix and suffix, then count the intersection.

3. Optimize with prefix/suffix arrays

Precompute prefix and suffix frequency arrays (or sets) to get distinct characters for any split in O(1). Then iterate through all splits and count those with intersection size > k.

4. Analyze complexity

State that preprocessing takes O(n * alphabet_size) time and O(n * alphabet_size) space, and the final iteration is O(n * alphabet_size) or O(n) with bitmasks.

5. Handle edge cases

Discuss cases like k >= alphabet_size, empty string, or when no valid split exists, and ensure the solution handles them correctly.

Key Points to Mention

  • Time and space complexity analysis
  • Use of prefix and suffix frequency arrays or bitmasks
  • Efficient computation of intersection size
  • Handling of edge cases (e.g., k=0, k >= number of distinct characters)
  • Trade-offs between different approaches (e.g., using sets vs. arrays)
  • Potential for further optimization if character set is small

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 costs, find the maximum number of packages you can form where each package has at most two items, all packages share the same total cost, and no item is used more than once.

Algorithms & Data Structures
Author's notes

This one tripped me up more.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints and edge cases, then propose an efficient algorithm. A good strategy is to sort the costs and use binary search on the target package cost, checking feasibility with a greedy two-pointer approach. Explain the time and space complexity and discuss potential optimizations.

Pro tip: Demonstrate Amazon's leadership principles by discussing trade-offs between different approaches and considering scalability for large inputs. Also, mention how you would test the solution with edge cases like duplicate costs and odd-length arrays.

1. Clarify the problem

Ask clarifying questions to ensure you understand the constraints: Can packages have one or two items? Is the array sorted? What are the possible values of costs? Can we assume all costs are positive integers?

2. Identify the core challenge

Recognize that the goal is to maximize the number of packages with a fixed total cost per package, using each item at most once. This is a combinatorial optimization problem that can be solved by checking feasibility for a given target cost.

3. Design an algorithm

Sort the array. For a candidate target cost, use a two-pointer technique to greedily form as many packages as possible: pair the smallest with the largest if their sum equals the target, otherwise adjust pointers. Also consider single-item packages if an item's cost equals the target.

4. Optimize with binary search

The number of packages is monotonic with respect to the target cost: if a target cost is feasible, any smaller target cost is also feasible. Use binary search over the possible target costs (from min to max sum of two items) to find the maximum feasible target cost.

5. Analyze complexity and test

State the time complexity: O(n log n) for sorting plus O(n log M) for binary search, where M is the range of possible costs. Discuss space complexity O(1) or O(n) depending on implementation. Walk through edge cases and test with examples.

Key Points to Mention

  • Sorting the array to enable efficient pairing
  • Two-pointer technique for checking feasibility of a target cost
  • Binary search on the target cost due to monotonicity
  • Handling single-item packages when an item's cost equals the target
  • Time and space complexity analysis
  • Edge cases: empty array, single item, all items same cost, no valid packages

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