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.

Microsoft Mülakat Sorusu – Intersection of Two Linked Lists

LeetCode içerisinde bulunan “Intersection of Two Linked Lists” sorusunun açıklaması ve çözümü. Bu soruda sizi verilen iki adet linked list‘in kesiştiği bir node var mı, varsa o node’u yoksa geriye null döndürmeniz isteniyor.

► LeetCode 160. Intersection of Two Linked Lists: https://leetcode.com/problems/intersection-of-two-linked-lists/

► Problem açıklaması:

Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.

For example, the following two linked lists begin to intersect at node c1:

The test cases are generated such that there are no cycles anywhere in the entire linked structure.

Note that the linked lists must retain their original structure after the function returns.

Custom Judge:

The inputs to the judge are given as follows (your program is not given these inputs):

intersectVal – The value of the node where the intersection occurs. This is 0 if there is no intersected node.

listA – The first linked list.

listB – The second linked list.

skipA – The number of nodes to skip ahead in listA (starting from the head) to get to the intersected node.

skipB – The number of nodes to skip ahead in listB (starting from the head) to get to the intersected node.

The judge will then create the linked structure based on these inputs and pass the two heads, headA and headB to your program. If you correctly return the intersected node, then your solution will be accepted.

Follow up: Could you write a solution that runs in O(n) time and use only O(1) memory?

LeetCode Çözümleri – Determine if String Halves Are Alike

LeetCode içerisinde bulunan “Determine if String Halves Are Alike” sorusunun açıklaması ve çözümü. Bu soruda sizi verilen bir string‘in ilk ve ikinci yarısındaki ünlü harf sayılarının eşit olup olmadığını bulmanız isteniyor.

► LeetCode 1704. Determine if String Halves Are Alike: https://leetcode.com/problems/determine-if-string-halves-are-alike/

► Problem açıklaması:

You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half.

Two strings are alike if they have the same number of vowels (‘a’, ‘e’, ‘i’, ‘o’, ‘u’, ‘A’, ‘E’, ‘I’, ‘O’, ‘U’). Notice that s contains uppercase and lowercase letters.

Return true if a and b are alike. Otherwise, return false.

Example 1:

Input: s = “book”

Output: true

Explanation: a = “bo” and b = “ok”. a has 1 vowel and b has 1 vowel. Therefore, they are alike.

Example 2:

Input: s = “textbook”

Output: false

Explanation: a = “text” and b = “book”. a has 1 vowel whereas b has 2. Therefore, they are not alike. Notice that the vowel o is counted twice.

Example 3:

Input: s = “MerryChristmas”

Output: false

Example 4:

Input: s = “AbCdEfGh”

Output: true

Constraints:

2 <= s.length <= 1000

s.length is even.

s consists of uppercase and lowercase letters.

LeetCode Çözümleri – Consecutive Characters

LeetCode içerisinde bulunan “Consecutive Characters” sorusunun açıklaması ve çözümü. Bu soruda sizi verilen bir string içerisinde, yan yana olan aynı karakterlerin maksimum sayısını bulmanız isteniyor.

► LeetCode 1446. Consecutive Characters: https://leetcode.com/problems/consecutive-characters/

► Problem açıklaması:

The power of the string is the maximum length of a non-empty substring that contains only one unique character.

Given a string s, return the power of s.

Example 1:

Input: s = “leetcode”

Output: 2

Explanation: The substring “ee” is of length 2 with the character ‘e’ only.

Example 2:

Input: s = “abbcccddddeeeeedcba”

Output: 5

Explanation: The substring “eeeee” is of length 5 with the character ‘e’ only.

Example 3:

Input: s = “triplepillooooow”

Output: 5

Example 4:

Input: s = “hooraaaaaaaaaaay”

Output: 11

Example 5:

Input: s = “tourist”

Output: 1

Constraints:

1 <= s.length <= 500

s consists of only lowercase English letters.