Загрузка страницы

Amazon Coding Interview (2019) - Jewels and Stones (LeetCode)

Jewels and Stones LeetCode coding solution. One of Amazon's most commonly asked interview questions according to LeetCode.

Coding InterviewsJewels and Stones (LeetCode) question and explanation.

This question is a commonly asked by the following companies:, Amazon, Adobe, and Alibaba.

Link to problem: https://leetcode.com/problems/jewels-and-stones/description/

Problem description: You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels.

The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so "a" is considered a different type of stone from "A".

Example 1:
Input: J = "aA", S = "aAAbbbb"
Output: 3

Example 2:
Input: J = "z", S = "ZZ"
Output: 0
Note:

S and J will consist of letters and have length at most 50.
The characters in J are distinct.

Intuition behind solution: Iterate through each character in J placing it in a hash set to represent the jewels. Then iterate through each character in S, asking if the current character exists in the jewels hash set. If it does, increment a count. Once the loop terminates, simply return the count.

Support me on Patreon: https://www.patreon.com/KevinNaughtonJr
Follow me on Twitter: https://twitter.com/KevinNaughtonJr
Follow me on Instagram: https://www.instagram.com/programeme
Follow me on GitHub: https://github.com/kdn251

Видео Amazon Coding Interview (2019) - Jewels and Stones (LeetCode) канала Kevin Naughton Jr.
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
16 октября 2018 г. 5:43:55
00:05:53
Яндекс.Метрика