All problems
0422EasyHash TableString

Refundable Drops

Tracked in this browser only
Write code

Trains the technique from

LeetCode 771Jewels and Stones

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

Examples

Example 1

Input
refundable = "aA", dropped = "aAAbb"
Output
3

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

Input
refundable = "z", dropped = "ZZZ"
Output
0

The depot pays on lowercase z, and all three containers carry the uppercase code, which is a different code.

Example 3

Input
refundable = "A", dropped = "bAcAb"
Output
2

Two of the five containers are stamped A, and each of those earns its own deposit.

Example 4

Input
refundable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", dropped = "abcdefghijklmnopqrstuvwxyz"
Output
0

Every capital letter is paid on and every container carries a small letter, so nothing in the sack matches.

Constraints

  • 1 <= refundable.length, dropped.length <= 50
  • refundable and dropped consist of English letters only.
  • All the characters of refundable are unique.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def num_jewels_in_stones(refundable: str, dropped: str) -> int:
Java
public int numJewelsInStones(String refundable, String dropped)
September 7
Apply