Katkat

Count partitions and equal-cost packages

AmazonSoftware Engineer · Online Assessment

Last updated

This question evaluates string-processing and combinatorial counting skills, including tracking distinct-character occurrences across contiguous partitions and using frequency-based pairing logic on arrays to form equal-cost packages.

Question

Given a string itemCategories, count the number of ways to partition it into exactly two contiguous non-empty substrings (a prefix and a suffix) such that the number of distinct characters appearing in both substrings is greater than k. Given an array itemCosts representing item costs, determine the maximum number of packages that can be created so that each package contains at most two items, all packages have the same total cost, and each item is used in at most one package.