This problem is from Leetcode. The problem statement in short is given below: Given a string of digits from 2 to 9, return all possible letter combinations that the number could represent, based on the classic phone keypad mapping. SOLUTION FIRST APPROACH See the code sample below : You can checkout the code from Github […]
4Sum – Leetcode #18
The problem statement in short is given below: Given an array of integers nums and an integer target, Find all unique quadruplets [a, b, c, d] in the array such that:a + b + c + d == target SOLUTION FIRST APPROACH You can checkout the code from Github here – 4Sum – Leetcode #18 […]
3Sum Closest – Leetcode #16
This problem is from Leetcode – 3Sum Closest. The problem statement in short is given below: Given an array nums of integers and an integer target, find the sum of three integers in nums such that the sum is closest to target. Assume there is only one solution. SOLUTION FIRST APPROACH Here we modify the […]
3Sum – Leetcode #15
PROBLEM STATEMENT This problem is from Leetcode – 3Sum. The problem statement in short is given below: Given an integer array nums, find all unique triplets [a, b, c] such that a + b + c = 0. Return a list of all such unique triplets. The solution set must not contain duplicate triplets. SOLUTION […]
Container With Most Water – Leetcode #11
PROBLEM STATEMENT This problem is from Leetcode – Container With Most Water. Problem statement i short is as below: Given an array of line heights, find two lines that form a container holding the most water. Return the maximum area, where area = distance × min height. SOLUTION FIRST APPROACH You can checkout the code […]
Zigzag Conversion – Leetcode #6
PROBLEM STATEMENT This problem is from Leetcode – Zigzag Conversion. The problem statement in short is given below: Write a string in a zigzag pattern on numRows rows, then read line-by-line to create a new string. SOLUTION FIRST APPROACH You can checkout he code from Github here: Zigzag conversion – First Approach. PERFORMANCE ANALYSIS COMPLEXITY […]
String to Integer (atoi) – Leetcode #8
PROBLEM STATEMENT This question is from Leetcode – String to Integer (atoi). The problem statement in short is given below: Implement a function that converts a string to a 32-bit signed integer. SOLUTION You can check out the code from Github here: String to Integer (atoi) – First Approach PERFORMANCE ANALYSIS RUNTIME 4 ms | […]
Student Attendance Record – Leetcode #551
PROBLEM STATEMENT This problem is from Leetcode Student Attendance Record. Problem statement in short is given below: Given a record string with ‘A’ (absent), ‘L’ (late), and ‘P’ (present), return true if there are fewer than 2 absences and no 3+ consecutive lates; else false. SOLUTION We can solve this problem in one pass. In […]
Detect Capital – Leetcode #520
This problem is from Leetcode – Detect Capital. Problem statement in short is as below: Return true if a word is all uppercase, all lowercase, or only the first letter is uppercase; otherwise, false. Solution To determine if the usage of capitals in a given word is correct according to the specified rules, we can […]
Fibonacci Number – Leetcode #509
Problem Statement This problem is from Leetcode – Fibonacci numbers. The problem statement in short is given below: Compute the nth Fibonacci number where F(0) = 0, F(1) = 1, and F(n) = F(n-1) + F(n-2) for n > 1. Solution: This problem is simple enough. Lets take the iterative approach first. See the code […]
Relative Ranks – Leetcode #506
Problem Statement This problem is from Leetcode – Relative Ranks. The problem statement in short is given below: Given an array of unique athlete scores, assign ranks where the top three receive “Gold Medal”, “Silver Medal”, “Bronze Medal”, and others receive their numeric rank. Return ranks in original order. Solution To solve the problem of […]
Max Consecutive Ones – Leetcode #485
Problem Statement This problem is from Leetcode – Max Consecutive Ones. The problem statement is as below: Given a binary array nums, return the length of the longest run of consecutive 1’s in the array. Solution Initialize variables Iterate Though the Array You can checkout the code from Github here: Max Consecutive Ones. See the […]
Number Complement – Leetcode #476
Problem Statement This problem is from Leetcode – Number Complement. The problem statement in short is as below: Given an integer num, return its binary complement by flipping all 0s to 1s and all 1s to 0s in its binary representation. Solution This problem is simple enough. We first compute the binary of the given […]
Assign Cookies – Leetcode #455
Problem Statement This problem is from Leetcode – Assign Cookies. The problem statement in short is as below: Given two arrays g (children’s greed factors) and s (cookie sizes), assign each child at most one cookie such that s[j] >= g[i] to satisfy the child. Return the maximum number of content children. Solution You can […]
Find All Numbers Disappeared in an Array – Leetcode #448
Problem Statement This problem is from Leetcode – Find All Numbers Disappeared in an Array. Given an array nums of n integers, where each nums[i] is in the range [1, n], find and return all integers in the range [1, n] that are missing from nums. Solution The solution to this problem is simple enough. […]