I am currently a FAANG aspirant who is documenting his journey towards cracking coding interview rounds for technology and product companies like Meta, Amazon, Google,Netflix, Adobe, Microsoft, etc. I will be solving and sharing the codes for questions from websites like leetcode, codeforces, codechef, etc. The primary programming language will be Python. Hope this helps any FAANG aspirant :)
Problem Statement: Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list . Return the linked list sorted as well . Example 1: Input: head = [1,2,3,3,4,4,5] Output: [1,2,5] Constraints : The number of nodes in the list is in the range [0, 300] . -100 <= Node.val <= 100 The list is guaranteed to be sorted in…
Problem Statement: Given the head of a linked list, remove the n th node from the end of the list and return its head. Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Constraints : The number of nodes in the list is sz . 1 <= sz <= 30 0 <= Node.val <= 100 1 <= n <= sz Source : https://leetcode.com/problems/remove-nth-node-from-end-of-list/ Asked in: Facebook Amazon , Apple Netflix…
Problem Statement: Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed) . Example 1: Input: root = [1,3,2,5,3,null,9] Output: [1,3,9] Constraints : The number of nodes in the tree will be in the range [0, 10 4 ] . -2 31 <= Node.val <= 2 31 - 1 Source : https://leetcode.com/problems/find-largest-value-in-each-tree-row/ Asked in: Facebook Amazon ,…
Problem Statement: Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center). Example 1: Input: root = [1,2,2,null,3,null,3] Output: false Constraints : The number of nodes in the tree is in the range [1, 1000] . -100 <= Node.val <= 100 Source : https://leetcode.com/problems/symmetric-tree/ Asked in: Facebook Amazon , Apple Leetcode Difficulty:…
Problem Statement: Given the root of a binary tree and an integer targetSum , return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum . A leaf is a node with no children. Example 1: Input: root = [1,2,3], targetSum = 5 Output: false Explanation: There two root-to-leaf paths in the tree: (1 --> 2): The sum is 3. (1 --> 3): The sum is 4.…
Problem Statement: Given the root of a binary tree, return the most frequent subtree sum . If there is a tie, return all the values with the highest frequency in any order. The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (including the node itself). Example 1: Input: root = [5,2,-3] Output: [2,-3,4] Constraints : The number of nodes…
Problem Statement: Given an array of strings words and an integer k , return the k most frequent strings . Return the answer sorted by the frequency from highest to lowest. Sort the words with the same frequency by their lexicographical order . Example 1: Input: words = ["the","day","is","sunny","the","the","the","sunny","is","is"], k = 4 Output: ["the","is","sunny","day"] Explanation: "the",…
Problem Statement: Given an array of points where points[i] = [x i , y i ] represents a point on the X-Y plane and an integer k , return the k closest points to the origin (0, 0) . The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x 1 - x 2 ) 2 + (y 1 - y 2 ) 2 ). You may return the answer in any order . The answer is guaranteed to be unique (except for the order…
Problem Statement: Given an integer array nums and an integer k , return the k most frequent elements . You may return the answer in any order . Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: [1] Constraints : 1 <= nums.length <= 10 5 k is in the range [1, the number of unique elements in the array] . It is guaranteed that the answer is…
Problem Statement: Given an integer array nums and an integer k , return the k th largest element in the array . Note that it is the k th largest element in the sorted order, not the k th distinct element. 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 <= k <= nums.length <= 10 4 -10 4 <= nums[i] <= 10 4 Source…
Problem Statement: Given an array of integers nums and an integer k , return the total number of continuous subarrays whose sum equals to k . Example 1: Input: nums = [1,1,1], k = 2 Output: 2 Example 2: Input: nums = [1,2,3], k = 3 Output: 2 Constraints: 1 <= nums.length <= 2 * 10 4 -1000 <= nums[i] <= 1000 -10 7 <= k <= 10 7 Source : https://leetcode.com/problems/subarray-sum-equals-k/ Leetcode…
Problem Statement: Given an integer array nums , find the contiguous subarray (containing at least one number) which has the largest sum and return its sum . A subarray is a contiguous part of an array Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. Example 2: Input: nums = [1] Output: 1 Constraints : 1 <= nums.length <= 10 5 -10 4 <=…
Problem Statement: Given an array of strings strs , group the anagrams together. You can return the answer in any order . An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Example 1: Input: strs = ["eat","tea","tan","ate","nat","bat"] Output: [["bat"],["nat","tan"],["ate","eat","tea"]] Example 2:…
Problem Statement: Given a string s , find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3: Input: s = "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3.…
Problem Statement: 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,1,3], k = 3 Output: true Example 2: Input: nums = [1,0,0,1,1], k = 1 Output: true Constraints: 1 <= nums.length <= 10 5 -10 9 <= nums[i] <= 10 9 0 <= k <= 10 5 Source :…