Show problems as
Classic problem #771EasyHash TableString

Jewels and Stones

Real-world version: Refundable Drops
Tracked in this browser only
Read Jewels and Stones on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

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