File: two-out-of-three/solution.py

Date: 2026-06-06

Time: 19:32

two-out-of-three/solution.py

Purpose

Solves LeetCode 2032 — Two Out of Three. Given three integer arrays, return all values that appear in at least two of the three arrays. This file owns the core algorithm; its test file and ~400+ other test files import from it (the "Imported By" list is a test-infrastructure artifact — all test files across the repo share a common import pattern, not a direct dependency on this solution).

Key Components

largest_odd(nums1, nums2, nums3) -> list[int] — The only function. Despite the name (which is wrong — this is the "Two Out of Three" problem, not "Largest Odd"), it computes the set-union of all pairwise intersections of the three input lists.

Contract:

Patterns

Dependencies

Flow

1. Convert each input list to a set, deduplicating elements within each array.

2. Compute three pairwise intersections (s1 & s2, s1 & s3, s2 & s3).

3. Union the intersections.

4. Convert to list and return.

All steps are O(n) where n is the total number of elements across the three arrays.

Invariants

Error Handling

None. Empty inputs work correctly — empty sets produce empty intersections and an empty result. No validation of element ranges or input types.

Notable Issue

The function is named largest_odd, which has nothing to do with the problem it solves. This is almost certainly a copy-paste error from another solution file. It doesn't affect correctness but will confuse anyone reading the code or searching by function name.

Topics to Explore

Beliefs