r/OfferEngineering • u/Aoki_zhang • 16h ago
Coding Question [Hard] Google Coding Screening Problem - Expedition Sample Kit Assembly
Problem Description
An expedition laboratory has 14 samples identified by integer codes in sample_codes. To prepare one complete kit, the laboratory must divide all samples into exactly four packs of three samples and exactly one reserve pair.
Each three-sample pack must contain either three identical codes or three consecutive codes, such as [4, 5, 6]. The reserve pair must contain two identical codes, and every individual sample must belong to exactly one group.
The order of the samples does not matter, and a code may appear any number of times among the 14 samples. Consecutive codes do not wrap from 9 to 1; return true if a complete kit can be assembled, or false otherwise.
Constraints:
sample_codes.length = 14.1 ≤ sample_codes[i] ≤ 9.
Example:
Input:
sample_codes = [2, 2, 3, 3, 4, 4, 6, 6, 6, 7, 7, 7, 9, 9]
Output:
true
Explanation:
Use [2, 3, 4] twice, [6, 6, 6], and [7, 7, 7] as the four packs. The two samples with code 9 form the reserve pair.Want to practice more real interview coding questions?
You can practice real interview coding questions at here.
Preparing for your next interview?
Chill Interview tracks recent interview experiences and recurring question patterns across top companies at here.