Leetcode Solutions

Leetcode solutions MLP Feature Image

[Solved] Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i – j) <= k.

Question Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i – j) <= k. Example 1: Input: nums = [1,2,3,1], k = 3 Output: true Example 2: Input: nums = [1,0,1,1], k = 1 Output: true Example 3: Input: nums = [1,2,3,1,2,3], k = 2 Output: false […]

[Solved] Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i – j) <= k. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

Question Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1: Input: nums = [1,2,3,1] Output: true Example 2: Input: nums = [1,2,3,4] Output: false Example 3: Input: nums = [1,1,1,3,3,4,3,2,4,2] Output: true Constraints: 1 <= nums.length <= 105 -109 <= nums[i] <= 109 Python Solution

[Solved] Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element.

Question Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element. You must solve it in O(n) time complexity. Example 1: Input: nums = [3,2,1,5,6,4], k = 2 Output: 5 Example 2: Input: nums = [3,2,3,1,2,4,5,5,6], k = 4 Output: 4 Constraints: 1

[Solved] Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given the head of a singly linked list, reverse the list, and return the reversed list.

Question Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: Input: head = [1,2] Output: [2,1] Example 3: Input: head = [] Output: [] Constraints: The number of nodes in the list is the range [0, 5000]. -5000 <= Node.val <= 5000

[Solved] Given the head of a singly linked list, reverse the list, and return the reversed list. Read More »

Leetcode solutions MLP Feature Image

[Solved] Write an algorithm to determine if a number n is happy. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits.

Question Write an algorithm to determine if a number n is happy. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits. Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does

[Solved] Write an algorithm to determine if a number n is happy. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits. Read More »

Leetcode solutions MLP Feature Image

[Solved] Write an SQL query to delete all the duplicate emails, keeping only one unique email with the smallest id. Note that you are supposed to write a DELETE statement and not a SELECT one.

Question SQL Schema Table: Person +————-+———+ | Column Name | Type | +————-+———+ | id | int | | email | varchar | +————-+———+ id is the primary key column for this table. Each row of this table contains an email. The emails will not contain uppercase letters. Write an SQL query to delete all the duplicate emails,

[Solved] Write an SQL query to delete all the duplicate emails, keeping only one unique email with the smallest id. Note that you are supposed to write a DELETE statement and not a SELECT one. Read More »

Leetcode solutions MLP Feature Image

[Solved] Write a function that takes an unsigned integer and returns the number of ‘1’ bits it has (also known as the Hamming weight).

Question Write a function that takes an unsigned integer and returns the number of ‘1’ bits it has (also known as the Hamming weight). Note: Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect

[Solved] Write a function that takes an unsigned integer and returns the number of ‘1’ bits it has (also known as the Hamming weight). Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an array, rotate the array to the right by k steps, where k is non-negative.

Question Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4] Example 2: Input: nums = [-1,-100,3,99], k = 2

[Solved] Given an array, rotate the array to the right by k steps, where k is non-negative. Read More »

Leetcode solutions MLP Feature Image

[Solved] Write an SQL query to report all the duplicate emails. Return the result table in any order.

Question SQL Schema Table: Person +————-+———+ | Column Name | Type | +————-+———+ | id | int | | email | varchar | +————-+———+ id is the primary key column for this table. Each row of this table contains an email. The emails will not contain uppercase letters. Write an SQL query to report all the

[Solved] Write an SQL query to report all the duplicate emails. Return the result table in any order. Read More »

Scroll to Top