The LeetCode problem “Combination Sum” asks us to find all unique combinations of numbers from a given list (array) that sum up to a specified target. Each number in the array can be used multiple times in the combination. For example, given the array [2, 3, 6, 7] and a…
3Sum Closest – 16. LeetCode
The LeetCode problem “3Sum Closest” asks us to find three numbers in an array that sum up to a value closest to a given target. For example, given an array nums = [-1, 2, 1, -4] and target 1, the three numbers closest to the target are [-1, 2, 1],…
Subarray Sum Equals K – 560. LeetCode
In the “Subarray Sum Equals K” problem, you are given an array of integers and a target integer, k. The goal is to find the number of contiguous subarrays within the array that sum up to k. Think of it as searching for specific sections in the array where adding…
Longest Common Prefix – 14. LeetCode
The LeetCode problem “Longest Common Prefix” requires finding the longest common starting sequence (prefix) among an array of strings. For example, given [“flower”, “flow” “flight”], the longest common prefix is “fl”. Algorithm and Data Structure Choice Chosen Algorithm: Vertical Scanning The vertical scanning technique checks each character position across all…
Meeting Rooms II – 253. LeetCode
The LeetCode problem “Meeting Rooms II” requires us to determine the minimum number of meeting rooms needed to accommodate a set of meetings with a given start and end times. For example, if we have meetings scheduled from (0, 30), (5, 10), and (15, 20), we need two meeting rooms…
Trapping Rain Water – 42. LeetCode
To solve the LeetCode problem “Trapping Rain Water”, we’re given an array representing an elevation map, where each element’s value is the height of that point. The goal is to calculate how much water can be trapped between the bars after it rains. Think of each bar as a wall,…
Compare Version Numbers – 165. LeetCode
To solve the Compare Version Numbers problem, we need to compare version strings like “1.0.0 and “1.0.1”. Each string is split by . to represent levels of the version, such as major.minor.patch. Our task is to compare these levels and determine which version is larger or if they are equal….
Two Sum LeetCode Interview Question (Explained Simply)
Given an array of integers and a target value, return the indices of 2 numbers that add up to the input target value. The first “two sum” in our example is 8 and 2, because they add up to 10. LeetCode also asks us to return the indices which are…
Design HashMap LeetCode Interview Question (Explained Simply)
Hash maps are used to store data in key-value pairs. They are similar to arrays because arrays values are stored against numeric keys known as indexes. Hash maps allow us to have flexible keys. The upside to hash maps is that they have lighting fast searches and insertions. The downside…
Missing Number LeetCode Question (Explained Simply)
Given an array of numbers, that are all distinct, return the only number in the range that is missing. This question wants you to find the missing number in sequence of arrays, example: In the example above, the number we want to find is 5. Steps