Count the stones whose type is a jewel, with case-sensitive matching

Quick Overview

Given a string of jewel types and a string of stones you hold, count how many of the stones are jewels, with uppercase and lowercase letters treated as different types. The problem tests fast membership checks, linear-time counting over a string, and careful handling of case-sensitive comparisons.

Count the stones whose type is a jewel, with case-sensitive matching

Company: Adobe

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

You're given a string `jewels` representing the types of stones that are jewels, and a string `stones` representing the stones you have. Each character in `stones` is a type of stone you have. Return how many of the stones you have are also jewels. Letters are case sensitive, so `"a"` is considered a different type of stone from `"A"`. ### Function Signature ```python def num_jewels_in_stones(jewels: str, stones: str) -> int: ``` ### Constraints - `1 <= len(jewels), len(stones) <= 50` - `jewels` and `stones` consist of only English letters. - All the characters of `jewels` are unique. ### Examples ```text Input: jewels = "aA", stones = "aAAbbbb" Output: 3 ``` The jewel types are 'a' and 'A'. In "aAAbbbb", 'a' appears once and 'A' appears twice, so 3 of the stones are jewels. ```text Input: jewels = "z", stones = "ZZ" Output: 0 ``` The only jewel type is lowercase 'z', and both stones are uppercase 'Z'. Since matching is case sensitive, none of the stones are jewels.

Overview: Given a string of jewel types and a string of stones you hold, count how many of the stones are jewels, with uppercase and lowercase letters treated as different types. The problem tests fast membership checks, linear-time counting over a string, and careful handling of case-sensitive comparisons.

Adobe logo
Adobe
Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

You're given a string jewels representing the types of stones that are jewels, and a string stones representing the stones you have. Each character in stones is a type of stone you have. Return how many of the stones you have are also jewels.

Letters are case sensitive, so "a" is considered a different type of stone from "A".

Function Signature

def num_jewels_in_stones(jewels: str, stones: str) -> int:

Constraints

  • 1 <= len(jewels), len(stones) <= 50
  • jewels and stones consist of only English letters.
  • All the characters of jewels are unique.

Examples

Input: jewels = "aA", stones = "aAAbbbb"
Output: 3

The jewel types are 'a' and 'A'. In "aAAbbbb", 'a' appears once and 'A' appears twice, so 3 of the stones are jewels.

Input: jewels = "z", stones = "ZZ"
Output: 0

The only jewel type is lowercase 'z', and both stones are uppercase 'Z'. Since matching is case sensitive, none of the stones are jewels.