← Amazon Interview Insights

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

Intermediate
Jun 2026

Summary

Amazon OA for a SWE role, one algorithmic problem involving region-based data distribution with affinity scores and pairing rules. The problem looked like a greedy question at first but the constraints make it way more involved.

Questions Asked (1)

Q1

Given an even number of data pieces each with an affinity value, distribute them across two regions by alternating selections. Certain pairs are linked so that picking one forces the other into the next region. Find the maximum total affinity achievable for region A.

Algorithms & Data Structures
Author's notes

I stared at this for a while before realizing it's not just a greedy pick-the-max problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a graph where each data piece is a node with a weight (affinity) and each linked pair is an edge. The alternating selection with forced placement implies that nodes are partitioned into two sets based on the parity of their selection order, and edges enforce that linked nodes must be in different sets. This is a maximum weight bipartite subgraph problem, which can be solved by reducing to min-cut or using a greedy approach if the graph is a collection of disjoint edges.

Pro tip: Clarify whether the linked pairs form a matching (each node in at most one pair) or a general graph; if it's a matching, the solution simplifies to choosing the larger weight from each pair. Also, consider that the alternating selection might impose additional constraints on the order, so verify if the problem is equivalent to partitioning into two independent sets with maximum weight.

1. Understand the problem and constraints

Restate the problem in your own words: we have an even number of items, each with an affinity value, and we must distribute them into two regions by alternating picks. Some pairs are linked such that picking one forces the other into the next region. We need to maximize the total affinity in region A.

2. Model as a graph

Represent each data piece as a vertex with weight equal to its affinity. Represent each linked pair as an edge. The alternating selection and forced placement imply that the two regions correspond to a bipartition of the vertices, and edges enforce that linked vertices are in different regions.

3. Identify the problem type

Recognize that this is a maximum weight bipartite subgraph problem (or maximum weight cut) if the graph is general, or a simpler maximum weight independent set on a bipartite graph if the links form a matching. Determine if the graph is bipartite or if the links are disjoint.

4. Choose an algorithm

If the links form a matching (each node in at most one pair), the optimal is to pick the larger weight from each pair for region A. If the graph is general, use a min-cut/max-flow reduction: create a source connected to all vertices with capacity equal to their weight, sink similarly, and edges between linked vertices with infinite capacity; the min-cut gives the optimal partition.

5. Analyze complexity and edge cases

Discuss the time complexity: O(V+E) for matching case, O(V^2 E) or better for min-cut. Consider edge cases: all affinities positive, negative affinities, disconnected components, and whether the alternating selection imposes an order that might affect feasibility.

Key Points to Mention

  • Graph representation: vertices as data pieces with weights, edges as linked pairs.
  • Bipartition constraint: linked pairs must be in different regions.
  • Maximum weight bipartite subgraph or maximum cut problem.
  • Min-cut/max-flow reduction for general graphs.
  • Greedy solution for matching case: choose max weight from each pair.
  • Time complexity and potential need for approximation if NP-hard.

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