Trains the technique from
LeetCode 771Jewels and StonesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A bottle-return depot stamps every container it accepts with a single letter code. The string refundable lists the codes the depot pays a deposit on, one letter per code, and no code appears in that list twice.
A customer empties a sack into the chute. The string dropped gives the code stamped on each container that went in, one letter per container, in the order they fell.
Codes are letters and the depot's stamping machine uses both cases, so 'd' and 'D' are two different codes and a deposit on one says nothing about the other.
Return how many of the dropped containers earn a deposit. A code that the depot pays on may of course turn up on several containers, and each of them earns its own deposit.
Example 1
Both cases of a are paid on. Three of the five containers carry one of them, and the two b containers carry a code the depot does not pay on.
Example 2
The depot pays on lowercase z, and all three containers carry the uppercase code, which is a different code.
Example 3
Two of the five containers are stamped A, and each of those earns its own deposit.
Example 4
Every capital letter is paid on and every container carries a small letter, so nothing in the sack matches.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def num_jewels_in_stones(refundable: str, dropped: str) -> int:public int numJewelsInStones(String refundable, String dropped)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.