Linkedin Mülakat Sorusu – Isomorphic Strings

LeetCode içerisinde bulunan “Isomorphic Strings” sorusunun açıklaması ve çözümü. Bu soruda sizi verilen iki string içerisinde, ilk string içerisindeki karakterlerin ikinci string içerisinde tam olarak map’lenmesinin olup olmadığı soruluyor.

► LeetCode 205. Isomorphic Strings: https://leetcode.com/problems/isomorphic-strings/

► Problem açıklaması:

Given two strings s and t, determine if they are isomorphic.

Two strings s and t are isomorphic if the characters in s can be replaced to get t.

All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.

Example 1:

Input: s = “egg”, t = “add”

Output: true

Example 2:

Input: s = “foo”, t = “bar”

Output: false

Example 3:

Input: s = “paper”, t = “title”

Output: true

Constraints:

1 <= s.length <= 5 * 10^4

t.length == s.length

s and t consist of any valid ascii character.

Google Mülakat Sorusu – Number of Good Pairs

LeetCode içerisinde bulunan “Number of Good Pairs” sorusunun açıklaması ve çözümü. Bu soruda sizi verilen bir integer dizisi içerisinde, “good pair”‘lerin sayısını döndürmeniz isteniyor. “Good pair” kavramı da i < j olmak üzere, nums[i] == nums[j] koşulunu sağlayan sayı çiftleri olarak tanımlanmış.

► LeetCode 1512. Number of Good Pairs: https://leetcode.com/problems/number-of-good-pairs/

► Problem açıklaması:

Given an array of integers nums, return the number of good pairs.

A pair (i, j) is called good if nums[i] == nums[j] and i < j.

Example 1:

Input: nums = [1,2,3,1,1,3]

Output: 4

Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.

Example 2:

Input: nums = [1,1,1,1]

Output: 6

Explanation: Each pair in the array are good.

Example 3:

Input: nums = [1,2,3]

Output: 0

Constraints:

1 <= nums.length <= 100

1 <= nums[i] <= 100

Bloomberg Mülakat Sorusu – Truncate Sentence

LeetCode içerisinde bulunan “Truncate Sentence” sorusunun açıklaması ve çözümü. Bu soruda size verilen bir string‘i, diğer verilen bir tam sayı kadar kelime içerecek şekilde sonundan kısaltmanız isteniyor.

► LeetCode 1816. Truncate Sentence: https://leetcode.com/problems/truncate-sentence/

► Problem açıklaması:

A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation).

For example, “Hello World”, “HELLO”, and “hello world hello world” are all sentences.

You are given a sentence s​​​​​​ and an integer k​​​​​​. You want to truncate s​​​​​​ such that it contains only the first k​​​​​​ words. Return s​​​​​​ after truncating it.

Example 1:

Input: s = “Hello how are you Contestant”, k = 4

Output: “Hello how are you”

Explanation:

The words in s are [“Hello”, “how” “are”, “you”, “Contestant”].

The first 4 words are [“Hello”, “how”, “are”, “you”].

Hence, you should return “Hello how are you”.

Example 2:

Input: s = “What is the solution to this problem”, k = 4

Output: “What is the solution”

Explanation:

The words in s are [“What”, “is” “the”, “solution”, “to”, “this”, “problem”].

The first 4 words are [“What”, “is”, “the”, “solution”].

Hence, you should return “What is the solution”.

Example 3:

Input: s = “chopper is not a tanuki”, k = 5

Output: “chopper is not a tanuki”

Constraints:

1 lessEqual s.length lessEqual 500

k is in the range [1, the number of words in s].

s consist of only lowercase and uppercase English letters and spaces.

The words in s are separated by a single space.

There are no leading or trailing spaces.

LeetCode Çözümleri – Sum of Digits in Base K

LeetCode içerisinde bulunan “Sum of Digits in Base K” sorusunun açıklaması ve çözümü. Bu soruda sizi verilen bir sayının, verilen bir taban’da karşılığının rakamları toplamı soruluyor.

► LeetCode 1837. Sum of Digits in Base K: https://leetcode.com/problems/sum-of-digits-in-base-k/

► Problem açıklaması:

Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k.

After converting, each digit should be interpreted as a base 10 number, and the sum should be returned in base 10.

Example 1:

Input: n = 34, k = 6

Output: 9

Explanation: 34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.

Example 2:

Input: n = 10, k = 10

Output: 1

Explanation: n is already in base 10. 1 + 0 = 1.

Constraints:

1 <= n <= 100

2 <= k <= 10

Amazon ve Microsoft Mülakat Sorusu – Letter Combinations of a Phone Number

LeetCode içerisinde bulunan “Letter Combinations of a Phone Number” sorusunun açıklaması ve çözümü. Bu soruda size bir cep telefonu üzerinde basılacak olan tuşların listesi verilip, olası yazılabilecek tüm mesaj kombinasyonları bir liste olarak geri döndürmeniz isteniyor.

► LeetCode 17. Letter Combinations of a Phone Number: https://leetcode.com/problems/letter-combinations-of-a-phone-number/

► Problem açıklaması:

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.

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 1:

Input: digits = “23”

Output: [“ad”,”ae”,”af”,”bd”,”be”,”bf”,”cd”,”ce”,”cf”]

Example 2:

Input: digits = “”

Output: []

Example 3:

Input: digits = “2”

Output: [“a”,”b”,”c”]

Constraints:

0 <= digits.length <= 4

digits[i] is a digit in the range [‘2’, ‘9’].

Amazon Mülakat Sorusu – Deepest Leaves Sum

LeetCode içerisinde bulunan “Deepest Leaves Sum” sorusunun açıklaması ve çözümü. Bu soruda size verilen bir binary tree‘nin en dipteki node’larının (leave) toplamını geri döndürmeniz isteniyor.

► LeetCode 1302. Deepest Leaves Sum: https://leetcode.com/problems/deepest-leaves-sum/

► Problem açıklaması:

Given the root of a binary tree, return the sum of values of its deepest leaves.

Example 1:

Input: root = [1,2,3,4,5,null,6,7,null,null,null,null,8]

Output: 15

Example 2:

Input: root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]

Output: 19

Constraints:

The number of nodes in the tree is in the range [1, 104].

1 <= Node.val <= 100

LeetCode Çözümleri – Check if the Sentence Is Pangram

LeetCode içerisinde bulunan “Check if the Sentence Is Pangram” sorusunun açıklaması ve çözümü. Bu soruda sizi verilen string‘in pangram, yani ingilizcedeki küçük harflerin en az bir defa bulunduğu bir string olup olmadığı soruluyor.

► LeetCode 1832. Check if the Sentence Is Pangram: https://leetcode.com/problems/check-if-the-sentence-is-pangram/

► Problem açıklaması:

A pangram is a sentence where every letter of the English alphabet appears at least once.

Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.

Example 1:

Input: sentence = “thequickbrownfoxjumpsoverthelazydog”

Output: true

Explanation: sentence contains at least one of every letter of the English alphabet.

Example 2:

Input: sentence = “leetcode”

Output: false

Constraints:

1 <= sentence.length <= 1000

sentence consists of lowercase English letters.

LeetCode Çözümleri – Thousand Separator

LeetCode içerisinde bulunan “Thousand Separator” sorusunun açıklaması ve çözümü. Bu soruda sizi verilen bir tam sayı için geriye binlik ayıracı olarak nokta koyduğunuz string halini döndürmeniz isteniyor.

Maalesef videoyu kaydederken bazı donmalar olmuş, kusura bakmayın.

► LeetCode 1556. Thousand Separator: https://leetcode.com/problems/thousand-separator/

► Problem açıklaması:

Given an integer n, add a dot (“.”) as the thousands separator and return it in string format.

Example 1:

Input: n = 987

Output: “987”

Example 2:

Input: n = 1234

Output: “1.234”

Example 3:

Input: n = 123456789

Output: “123.456.789”

Example 4:

Input: n = 0

Output: “0”

Constraints:

0 <= n < 2^31

Microsoft Mülakat Sorusu – Spiral Matrix

LeetCode içerisinde bulunan “Spiral Matrix” sorusunun açıklaması ve çözümü. Bu soruda size verilen bir matrix (C# için jagged array) elemanlarını spiral bir şekilde geriye döndürmeniz isteniyor.

► LeetCode 54. Spiral Matrix: https://leetcode.com/problems/spiral-matrix/

► Problem açıklaması:

Given an m x n matrix, return all elements of the matrix in spiral order.

Example 1:

Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]

Output: [1,2,3,6,9,8,7,4,5]

Example 2:

Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]

Output: [1,2,3,4,8,12,11,10,9,5,6,7]

Constraints:

m == matrix.length

n == matrix[i].length 1 <= m, n <= 10

-100 <= matrix[i][j] <= 100

Microsoft & Amazon Mülakat Sorusu – Merge Two Sorted Lists

LeetCode içerisinde bulunan “Merge Two Sorted Lists” sorusunun açıklaması ve çözümü. Bu soruda size sıralı olarak verilen iki tane linked list‘i birleştirip yine sıralı olarak döndürmeniz isteniyor.

► LeetCode 21. Merge Two Sorted Lists: https://leetcode.com/problems/merge-two-sorted-lists/

► Problem açıklaması:

Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists.

Example 1:

Input: l1 = [1,2,4], l2 = [1,3,4]

Output: [1,1,2,3,4,4]

Example 2:

Input: l1 = [], l2 = []

Output: []

Example 3:

Input: l1 = [], l2 = [0]

Output: [0]

Constraints:

The number of nodes in both lists is in the range [0, 50].

-100 <= Node.val <= 100

Both l1 and l2 are sorted in non-decreasing order.