Smallest Cart Total That Still Unlocks Free Shipping

Last updated: November 29, 2026

Quick Overview

A shop gives free shipping when the cart subtotal reaches a threshold (for example 3,980 yen). Given wishlist item prices, choose a subset whose total meets the threshold while being as small as possible, and return that total and the chosen items.

Rakuten
Coding & Algorithms
Software Engineer
Rakuten
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


A shop gives free shipping when the cart subtotal reaches a threshold (for example 3,980 yen). Given wishlist item prices, choose a subset whose total meets the threshold while being as small as possible, and return that total and the chosen items.

Ichiba shops widely use a 3,980 yen free shipping line, and a cart helper that suggests the cheapest way to clear it is a natural product feature. The interviewer wants to see 0/1 subset sum DP, a tight upper bound on the DP range, and reconstruction of the chosen items.

What the Interviewer Expects
  • Model it as 0/1 subset sum, not unbounded
  • Bound the DP range by threshold plus max price
  • Iterate sums downward so each item is used once
  • Reconstruct chosen items with parent pointers
  • Return None when even the full wishlist is short
Key Topics to Cover
dynamic programming
subset sum
knapsack
reconstruction
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Items can be bought in any quantity. What changes in the loop?
  • Prices are up to 100,000 yen and there are 500 items. Is pseudo-polynomial DP still fine?
  • Prefer the solution with the fewest items among equal totals.
  • Points can cover part of the price. How does that interact with the threshold?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Prices are positive integers in yen, each item can be chosen at most once. Find the minimum achievable subset total S with S >= threshold. Return (S, indices) or None....

High-Level Design

Classic reachability DP: reach[s] says whether some subset sums to s. We do not need sums up to the full wishlist total. If S is the optimal total, removing any item from that subset drops below the...


Submit Your Answer
Markdown supported