← Amazon questions

Largest Item Association Group

Filed under Amazon

Free read 3 of 3

Check if inputs are given as list of pairs, and whether items are always strings.

The question

Given pairs of associated items, find the largest group of associated items. If groups are equal in size, return the one that is lexicographically smallest.

Constraints

  • Item names are strings
  • Associations are bidirectional and transitive

Examples

Input
assoc = [['item1', 'item2'], ['item3', 'item4'], ['item1', 'item4']]
Output
['item1', 'item2', 'item3', 'item4']
Why
All items form a single connected component of size 4.

Approach

  1. Check if inputs are given as list of pairs, and whether items are always strings.

Tips

  • What they are testing: Test disconnected components and ties in group sizes requiring alphabetical tie-breaking.
  • Common mistake: Failing to normalize root representatives or missing lexicographical sorting on the resulting groups.

Related Amazon questions

Collected from public candidate posts and coding forums. Updated Nov 2026.