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

GOOGLE CODING INTERVIEW QUESTION - LETTER COMBINATIONS OF A PHONE NUMBER (LeetCode)

Letter Combinations of a Phone Number LeetCode coding solution. One of Google's most commonly asked interview questions according to LeetCode.

Coding Interviews Letter Combinations of a Phone Number (LeetCode) question and explanation.

This question is a commonly asked by the following companies: Google, Facebook, Amazon, Microsoft, Uber, JPMorgan, and Morgan Stanley.

Link to problem: https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/

Problem description: Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.

A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.

Example:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].

Note: Although the above answer is in lexicographical order, your answer could be in any order you want.

Intuition behind solution: Create a mapping for digits to letters (i.e. 2 represent the letters a, b, and c). Call a recursive function to populate or letter combinations. Pass the recursive function our array list (result) that holds all our completed combinations, the numbers we're given, the mapping from numbers to letters, the current index we are on, and a string representing our current combination. Inside each recursive call, check if we have traversed all the digits we are given (index == digits.length()), if we have, add the current combination to our result and return to ensure we don't continue. Otherwise, get the letter mapping for the current digit we're on given by (mapping[digits.charAt(i) - '0'). Iterate through each possible letter that the current digit represents and at each iteration pass to the next recursive call letters[i], updating our representation of our current combination (current + letters[i]) and our index (index + 1). Once all the recursive calls terminate, we have successfully generated all possible letter combinations so we return result.

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
My Desk Setup
Desk - https://bit.ly/3jfY195
Chair - https://amzn.to/2O9TM3r
Monitor - https://amzn.to/3rcSHGa
Webcam - https://amzn.to/2NUmwgi
Desktop - https://amzn.to/3tiySPL
Laptops - https://amzn.to/3aRoN3Z
iPad - https://amzn.to/2LlJzzJ
Keyboard - https://amzn.to/3jfbxdd
Mouse - https://amzn.to/36ElWtT
Wrist Rest - https://amzn.to/3trrHF4 (pls don't buy this)
Mouse Pad - https://amzn.to/2Myz2lt
Microphone - https://amzn.to/3atNyTA
Lamp - https://amzn.to/3jjfZYp
Headphones - https://amzn.to/3tvr0KU (new model)
Headphone Hook - https://amzn.to/3tr8uTC
Blue Light Glasses - https://amzn.to/3cDVUdK
Wireless Charger - https://amzn.to/39LY1uu
Keyboard cable - https://amzn.to/2O5p2R5
Mic arm - https://amzn.to/3cECZj8
Audio interface - https://amzn.to/36HdWIi
Cloudlifter - https://amzn.to/36VO6kf
Laptop dock - https://amzn.to/2O2DsBw
Motherboard - https://amzn.to/3rkiWuA
Solid state - https://amzn.to/3rk5vuo
CPU cooler - https://amzn.to/3tnwwPA
CableMod - https://amzn.to/3tqbtM8
CPU - https://amzn.to/3auG1ns
Power supply - https://amzn.to/3trsAxo
RAM - https://amzn.to/39JZcuf
Designing Data-Intensive Applications - https://amzn.to/2YK4ek1
Clean Code - https://amzn.to/3txqfB5
Meditations - https://amzn.to/3cDa4fi

Видео GOOGLE CODING INTERVIEW QUESTION - LETTER COMBINATIONS OF A PHONE NUMBER (LeetCode) канала Kevin Naughton Jr.
Показать
Комментарии отсутствуют
Введите заголовок:

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

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

Зарегистрируйтесь или войдите с
Информация о видео
12 октября 2018 г. 6:10:42
00:13:32
Яндекс.Метрика