Solve string partition and equal-sum package problems
Overview
This question evaluates algorithm design and data-structure competence in string processing and array pairing, specifically counting distinct-character intersections across string partitions and maximizing equal-sum packages from item costs.
Amazon
Aug 1, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
0
0
Given a string itemCategories (lowercase English letters) and an integer k (0 ≤ k ≤
26), count the number of indices i (1 ≤ i < n) that partition the string into a non-empty prefix and a non-empty suffix such that the number of distinct characters that appear in both the prefix and the suffix is strictly greater than k. Return the count. Constraints: 1 ≤ n ≤ 1e5.
Given an array itemCosts of n item prices, create packages where each package contains at most two items and every package has the same total cost S. Each item can be used in at most one package. Choose S to maximize the number of packages and return that maximum. Single-item packages are allowed only if their cost equals S; two-item packages are allowed only if their costs sum to S. Explain your approach and time complexity.