Tag Archives: leetcode çözümleri

LeetCode Çözümlerİ – 181. Employees Earning More Than Their Managers

LeetCode içerisinde bulunan “Employees Earning More Than Their Managers”‘ sorusunun açıklaması ve çözümü.

🔥 LeetCode 181. Employees Earning More Than Their Managers: https://leetcode.com/problems/employees-earning-more-than-their-managers/

➡️ Problem açıklaması:

The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.

+—-+——-+——–+———–+

| Id | Name | Salary | ManagerId |

+—-+——-+——–+———–+

| 1 | Joe | 70000 | 3 |

| 2 | Henry | 80000 | 4 |

| 3 | Sam | 60000 | NULL |

| 4 | Max | 90000 | NULL |

+—-+——-+——–+———–+

Given the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.

+———-+

| Employee |

+———-+

| Joe |

+———-+

LeetCode Çözümlerİ – 183. Customers Who Never Order

LeetCode içerisinde bulunan “Customers Who Never Order”‘ sorusunun açıklaması ve çözümü.

🔥 LeetCode 183. Customers Who Never Order: https://leetcode.com/problems/customers-who-never-order/

➡️ Problem açıklaması:

Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.

Table: Customers.

+—-+——-+

| Id | Name |

+—-+——-+

| 1 | Joe |

| 2 | Henry |

| 3 | Sam |

| 4 | Max |

+—-+——-+

Table: Orders.

+—-+————+

| Id | CustomerId |

+—-+————+

| 1 | 3 |

| 2 | 1 |

+—-+————+

Using the above tables as example, return the following:

+———–+

| Customers |

+———–+

| Henry |

| Max |

+———–+

LeetCode Çözümlerİ – 176. Second Highest Salary

LeetCode içerisinde bulunan “Second Highest Salary”‘ sorusunun açıklaması ve çözümü.

🔥 LeetCode 176. Second Highest Salary: https://leetcode.com/problems/second-highest-salary/

➡️ Problem açıklaması:

Write a SQL query to get the second highest salary from the Employee table.

+—-+——–+

| Id | Salary |

+—-+——–+

| 1 | 100 |

| 2 | 200 |

| 3 | 300 |

+—-+——–+

For example, given the above Employee table, the query should return 200 as the second highest salary. If there is no second highest salary, then the query should return null.

+———————+

| SecondHighestSalary |

+———————+

| 200 |

+———————+

LeetCode Çözümleri – 182. Duplicate Emails

LeetCode içerisinde bulunan “Duplicate Emails”‘ sorusunun açıklaması ve çözümü.

🔥 LeetCode 182. Duplicate Emails: https://leetcode.com/problems/duplicate-emails/

➡️ Problem açıklaması:

Write a SQL query to find all duplicate emails in a table named Person.

+—-+———+

| Id | Email |

+—-+———+

| 1 | a@b.com |

| 2 | c@d.com |

| 3 | a@b.com |

+—-+———+

For example, your query should return the following for the above table:

+———+

| Email |

+———+

| a@b.com |

+———+

☢️ Note: All emails are in lowercase.

LeetCode Çözümleri – 172. Factorial Trailing Zeroes

LeetCode içerisinde bulunan “Factorial Trailing Zeroes”‘ sorusunun açıklaması ve çözümü.

🔥 LeetCode 172. Factorial Trailing Zeroes: https://leetcode.com/problems/factorial-trailing-zeroes/

➡️ Problem açıklaması:

Given an integer n, return the number of trailing zeroes in n!.

Example 1:

Input: 3

Output: 0

Explanation: 3! = 6, no trailing zero.

Example 2:

Input: 5

Output: 1

Explanation: 5! = 120, one trailing zero.

☢️ Note: Your solution should be in logarithmic time complexity.

LeetCode Çözümleri – 125. Valid Palindrome – [Facebook ve Apple Mülakat Sorusu]

LeetCode içerisinde bulunan “Valid Palindrome”‘ sorusunun açıklaması ve çözümü. Bu soruda verilen bir string’in içindeki sadece alfanümerik karakterleri göz önüne alarak bu string’in bir palindrom olup olmadığını bulmamızı istiyor. LeetCode’a göre Facebook ve Apple mülakatlarında sorulmuş sorulardan biri.

🔥 LeetCode 125. Valid Palindrome: https://leetcode.com/problems/valid-palindrome/

🔥 Palindrom nedir? https://tr.wikipedia.org/wiki/Palindrom

➡️ Problem açıklaması:

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Note: For the purpose of this problem, we define empty string as valid palindrome.

Example 1:

Input: “A man, a plan, a canal: Panama”

Output: true

Example 2:

Input: “race a car”

Output: false

Constraints: s consists only of printable ASCII characters.

LeetCode Çözümleri – 88. Merge Sorted Array

LeetCode içerisinde bulunan “Merge Sorted Array”‘ sorusunun açıklaması ve çözümü.

🔥 LeetCode 88. Merge Sorted Array: https://leetcode.com/problems/merge-sorted-array/

➡️ Problem açıklaması:

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.

Note:

The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.

Example:

Input: nums1 = [1,2,3,0,0,0], m = 3

nums2 = [2,5,6], n = 3

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

LeetCode Çözümleri – 83. Remove Duplicates from Sorted List – [Facebook ve Google Mülakat Sorusu]

LeetCode içerisinde bulunan “Remove Duplicates from Sorted List”‘ sorusunun açıklaması ve çözümü.

🔥 LeetCode 83. Remove Duplicates from Sorted List: https://leetcode.com/problems/remove-duplicates-from-sorted-list/

🔥 Bahsi geçen Linked List yazısı: https://www.cs.cmu.edu/~adamchik/15-121/lectures/Linked%20Lists/linked%20lists.html

➡️ Problem açıklaması:

Given a sorted linked list, delete all duplicates such that each element appear only once.

Example 1:

Input: 1–1–2

Output: 1–2

Example 2:

Input: 1–1–2–3–3

Output: 1–2–3

LeetCode Çözümleri – 70. Climbing Stairs [Amazon ve Goldman Sachs Mülakat Sorusu]

LeetCode içerisinde bulunan “Climbing Stairs”‘ sorusunun açıklaması ve çözümü. Bu soruda N basamaktan oluşan bir merdivenimiz var ve bu merdiveni çıkarken ya 1 basamak, ya da 2 basamak çıkabiliyoruz tek adımda. Bu merdiveni kaç farklı şekilde tırmanabiliriz? Leetcode’a göre Amazon ve Goldman Sachs’ta mülakatlarında sorulmuş sorulardan biri.

🔥 LeetCode 70. Climbing Stairs: https://leetcode.com/problems/climbing-stairs/

➡️ Problem açıklaması:

You are climbing a stair case. It takes n steps to reach to the top.

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

Note: Given n will be a positive integer.

Example 1:

Input: 2

Output: 2

Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps

Example 2:

Input: 3

Output: 3

Explanation: There are three ways to climb to the top. 1. 1 step + 1 step + 1 step 2. 1 step + 2 steps 3. 2 steps + 1 step

LeetCode Çözümleri – 69. Sqrt(x)

LeetCode içerisinde bulunan “Sqrt(x)”‘ sorusunun açıklaması ve çözümü. Bu soruda tamsayı bir parametre alan metodunuzdan geriye o sayının karekökünün tam sayı halini döndürmenizi istiyor. Tabi bunun için hali hazırda kullandığınız programlama dilinde var olan sqrt() gibi metodları kullanmamanız gerekmekte.

🔥 LeetCode 69. Sqrt(x): https://leetcode.com/problems/sqrtx/

➡️ Problem açıklaması:

Implement int sqrt(int x).

Compute and return the square root of x, where x is guaranteed to be a non-negative integer.

Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned.

Example 1:

Input: 4

Output: 2

Example 2:

Input: 8

Output: 2

Explanation: The square root of 8 is 2.82842…, and since the decimal part is truncated, 2 is returned.