PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/Amazon

Solve string partition and equal-sum package problems

Last updated: Mar 29, 2026

Quick 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.

  • Medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Solve string partition and equal-sum package problems

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Take-home Project

1) 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. 2) 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.

Quick Answer: 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.

Related Interview Questions

  • Find Valid IP Addresses in Files - Amazon (medium)
  • Implement Optimal Bucket Batching - Amazon (hard)
  • Implement Cache and Rotate Matrix - Amazon (medium)
  • Find Longest Activatable Server Streak - Amazon (hard)
  • Build the Largest Available Sequence - Amazon (medium)
Amazon logo
Amazon
Aug 1, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
1
0
  1. 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.
  2. 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.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.