Tag Archives: leetcode çözümleri

LeetCode Çözümlerİ – 520. Detect Capital [Google Mülakat Sorusu]

LeetCode içerisinde bulunan “Detect Capital”‘ sorusunun açıklaması ve çözümü. Bu soruda verilen stringin büyük harf kuralına göre uygun olup olmadığı soruluyor. Google mülakat sorusu.

🔥 LeetCode 520. Detect Capital: https://leetcode.com/problems/detect-capital/

➡️ Problem açıklaması:

Given a word, you need to judge whether the usage of capitals in it is right or not.

We define the usage of capitals in a word to be right when one of the following cases holds:

All letters in this word are capitals, like “USA”.

All letters in this word are not capitals, like “leetcode”.

Only the first letter in this word is capital, like “Google”.

Otherwise, we define that this word doesn’t use capitals in a right way.

Example 1:

Input: “USA”

Output: True

Example 2:

Input: “FlaG”

Output: False

Note: The input will be a non-empty word consisting of uppercase and lowercase latin letters.

LeetCode Çözümlerİ – 896. Monotonic Array [Facebook Mülakat Sorusu]

LeetCode içerisinde bulunan “Monotonic Array”‘ sorusunun açıklaması ve çözümü. Bu soruda verilen bir dizinin monotonik (düzenli olarak artan veya düzenli olarak azalan) olup olmadığı soruluyor. LeetCode’a göre bu bir Facebook mülakat sorusu.

🔥 LeetCode 896. Monotonic Array: https://leetcode.com/problems/monotonic-array/

➡️ Problem açıklaması:

An array is monotonic if it is either monotone increasing or monotone decreasing.

An array A is monotone increasing if for all i LessOrSmaller= j, A[i] LessOrSmaller= A[j]. An array A is monotone decreasing if for all i LessOrSmaller= j, A[i]LessOrBigger= A[j].

Return true if and only if the given array A is monotonic.

Example 1:

Input: [1,2,2,3]

Output: true

Example 2:

Input: [6,5,4,4]

Output: true

Example 3:

Input: [1,3,2]

Output: false

Example 4:

Input: [1,2,4,5]

Output: true

Example 5:

Input: [1,1,1]

Output: true

Note:

1 <= A.length <= 50000

-100000 <= A[i] <= 100000

LeetCode Çözümlerİ – 231. Single Number [Amazon Mülakat Sorusu]

LeetCode içerisinde bulunan “Add Strings”‘ sorusunun açıklaması ve çözümü. Bu soruda string olarak verilen iki sayının toplamını bulmanız isteniyor fakat herhangi bir hazır metod kullanamıyorsunuz. LeetCode’a göre Facebook mülakatlarında sorulmuş sorulardan biri.

🔥 LeetCode 231. Single Number: https://leetcode.com/problems/single-number/

➡️ Problem açıklaması:

Given a non-empty array of integers, every element appears twice except for one. Find that single one.

Note:

Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

Example 1:

Input: [2,2,1]

Output: 1

Example 2:

Input: [4,1,2,1,2]

Output: 4

LeetCode Çözümlerİ – 929. Unique E-Mail Address [Google Mülakat Sorusu]

LeetCode içerisinde bulunan “Unique E-Mail Address”‘ sorusunun açıklaması ve çözümü. Bu soruda verilen email adreslerinden mail adresi kuralları ile tekil olanları döndürmeniz iztenmekte. LeetCode’a göre Google mülakatlarında sorulmuş sorulardan biri.

🔥 LeetCode 929. Unique E-Mail Address https://leetcode.com/problems/unique-email-addresses/

➡️ Problem açıklaması:

Every email consists of a local name and a domain name, separated by the @ sign.

For example, in alice@leetcode.com, alice is the local name, and leetcode.com is the domain name.

Besides lowercase letters, these emails may contain ‘.’s or ‘+’s.

If you add periods (‘.’) between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name. For example, “alice.z@leetcode.com” and “alicez@leetcode.com” forward to the same email address. (Note that this rule does not apply for domain names.)

If you add a plus (‘+’) in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered, for example m.y+name@email.com will be forwarded to my@email.com. (Again, this rule does not apply for domain names.)

It is possible to use both of these rules at the same time.

Given a list of emails, we send one email to each address in the list. How many different addresses actually receive mails?

Example 1:

Input: [“test.email+alex@leetcode.com”,”test.e.mail+bob.cathy@leetcode.com”,”testemail+david@lee.tcode.com”]

Output: 2

Explanation: “testemail@leetcode.com” and “testemail@lee.tcode.com” actually receive mails

Note:

1 LessOrSmaller= emails[i].length LessOrSmaller= 100

1 LessOrSmaller= emails.length LessOrSmaller= 100

Each emails[i] contains exactly one ‘@’ character.

All local and domain names are non-empty.

Local names do not start with a ‘+’ character.

LeetCode Çözümlerİ – 917. Reverse Only Letters [Microsoft Mülakat Sorusu]

LeetCode içerisinde bulunan “Reverse Only Letters”‘ sorusunun açıklaması ve çözümü. Bu soruda verilen sadece string içerisindeki harfleri tersinden yazdırmanız isteniyor. LeetCode’a göre Microsoft mülakatlarında sorulmuş sorulardan biri.

🔥 LeetCode 917. Reverse Only Letters: https://leetcode.com/problems/reverse-only-letters/

➡️ Problem açıklaması:

Given a string S, return the “reversed” string where all characters that are not a letter stay in the same place, and all letters reverse their positions.

Example 1:

Input: “ab-cd”

Output: “dc-ba”

Example 2:

Input: “a-bC-dEf-ghIj”

Output: “j-Ih-gfE-dCba”

Example 3:

Input: “Test1ng-Leet=code-Q!”

Output: “Qedo1ct-eeLg=ntse-T!”

Note: S.length LessOrSmaller= 100

33 LessOrSmaller= S[i].ASCIIcode LessOrSmaller= 122

S doesn’t contain \ or “

LeetCode Çözümlerİ – 415. Add Strings [Facebook Mülakat Sorusu]

LeetCode içerisinde bulunan “Add Strings”‘ sorusunun açıklaması ve çözümü. Bu soruda string olarak verilen iki sayının toplamını bulmanız isteniyor fakat herhangi bir hazır metod kullanamıyorsunuz. LeetCode’a göre Facebook mülakatlarında sorulmuş sorulardan biri.

🔥 LeetCode 415. Add Strings: https://leetcode.com/problems/add-strings/

➡️ Problem açıklaması:

Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.

Note:

The length of both num1 and num2 is LessOrSmaller 5100.

Both num1 and num2 contains only digits 0-9.

Both num1 and num2 does not contain any leading zero.

You must not use any built-in BigInteger library or convert the inputs to integer directly.

LeetCode Çözümlerİ – 414. Third Maximum Number

LeetCode içerisinde bulunan “Third Maximum Number”‘ sorusunun açıklaması ve çözümü. Bu soruda verilen bir dizi içerisinde bulunan 3. en yüksek sayıyı döndürmeniz istenmekte.

🔥 LeetCode 414. Third Maximum Number: https://leetcode.com/problems/third-maximum-number/

➡️ Problem açıklaması:

Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).

Example 1:

Input: [3, 2, 1]

Output: 1

Explanation: The third maximum is 1.

Example 2:

Input: [1, 2]

Output: 2

Explanation: The third maximum does not exist, so the maximum (2) is returned instead.

Example 3:

Input: [2, 2, 3, 1]

Output: 1

Explanation: Note that the third maximum here means the third maximum distinct number. Both numbers with value 2 are both considered as second maximum.

LeetCode Çözümlerİ – 1480. Running Sum Of 1D Array

LeetCode içerisinde bulunan “Running Sum Of 1D Array”‘ sorusunun açıklaması ve çözümü. Bu soruda tek boyutlu bir dizide her bir eleman için, o elemana olan kadar gelen elemanların toplamını yazdırmanız istenmekte.

🔥 LeetCode 1480. Running Sum Of 1D Array: https://leetcode.com/problems/running-sum-of-1d-array/

➡️ Problem açıklaması:

Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).

Return the running sum of nums.

Example 1:

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

Output: [1,3,6,10]

Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].

Example 2:

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

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

Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].

Example 3:

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

Output: [3,4,6,16,17]

Constraints:

1 <= nums.length <=1000

-10^6 <= nums[i] <= 10^6

LeetCode Çözümlerİ – 13. Roman to Integer

LeetCode içerisinde bulunan “Roman to Integer”‘ sorusunun açıklaması ve çözümü. Bu soruda size verilen roma rakamlarından oluşan sayının tam sayı hali isteniyor.

🔥 LeetCode 13. Roman to Integer: https://leetcode.com/problems/roman-to-integer

➡️ Problem açıklaması:

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

Symbol Value

I 1

V 5

X 10

L 50

C 100

D 500

M 1000

For example, two is writt en as II in Roman numeral, just two one’s added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, which is XX + V + II.

Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

I can be placed before V (5) and X (10) to make 4 and 9.

X can be placed before L (50) and C (100) to make 40 and 90.

C can be placed before D (500) and M (1000) to make 400 and 900.

Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.

Example 1:

Input: “III”

Output: 3

Example 2:

Input: “IV”

Output: 4

Example 3:

Input: “IX”

Output: 9

Example 4:

Input: “LVIII”

Output: 58

Explanation: L = 50, V= 5, III = 3.

Example 5:

Input: “MCMXCIV”

Output: 1994

Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.

LeetCode Çözümlerİ – 404. Sum of Left Leaves [Facebook Mülakat Sorusu]

LeetCode içerisinde bulunan “Sum of Left Leaves”‘ sorusunun açıklaması ve çözümü. Bu soruda size verilen bir binary tree içerisindeki “left leaves” (ağacın en solunda olan ve alt node’ları olmayan) node’larının toplamı soruluyor. LeetCode’a göre bu soru daha önce Facebook mülakatlarında sorulan sorulardan biridir.

🔥 LeetCode 404. Sum of Left Leaves: https://leetcode.com/problems/sum-of-left-leaves/

➡️ Problem açıklaması: Find the sum of all left leaves in a given binary tree.

Example:

3

/ \

9 20

/ \

15 7

There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.