0% completed
Jewels and Stones (easy)
Problem Statement
Given two strings. The first string represents types of jewels, where each character is a unique type of jewel. The second string represents stones you have, where each character represents a type of stone. Determine how many of the stones you have are also jewels.
Examples:
-
Example 1:
- Input: Jewels = "abc", Stones = "aabbcc"
- Expected Output: 6
- Justification: All the stones are jewels.
-
Example 2:
- Input: Jewels = "aA", Stones = "aAaZz"
- Expected Output: 3
- Justification: There are 2 'a' and 1 'A' stones that are jewels.
3
.....
.....
.....
lenkadan
· 9 months ago
Time complexity O(n+m) should be further reduced. O (n) is the length of jewels, where each character is a unique jewel as per problem description.
As the input is limited by the finite number of letters of English alphabet and the uniqueness of jewels will not make the length of Jewels string grow by duplicating characters, this input should be considered a constant as it does not scale. So O(n+m) where n is constant, should be reduced to O(m) for m = length of stones string