Repository navigation
Array and Strings
This lists out the various questions needed to be solved in arrays :-
-
3-SUM -
Find all the triplets in an array that sum up to zero.- Article - https://www.geeksforgeeks.org/find-triplets-array-whose-sum-equal-zero/
- LeetCode Solution - https://leetcode.com/problems/3sum/discuss/140004/C++-optimized-O(n2)-solution (Modified so that duplicate triplets are returned).
-
K-SUM -
Find all triplets that sum up to a given value.- Article - https://www.geeksforgeeks.org/find-a-triplet-that-sum-to-a-given-value/
- Similar as 3-SUM, just tweak 0 to be k.
-
3-SUM CLOSEST -
Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target.- LeetCode Solution - https://leetcode.com/problems/3sum-closest/discuss/140006/C++-solution
- Modified 3-SUM question.
-
4-SUM -
Find four elements that sum to a given value- Article - https://www.geeksforgeeks.org/?p=23327
- O(n^2logn) and O(n^2) solution - https://www.geeksforgeeks.org/find-four-elements-that-sum-to-a-given-value-set-2/
-
First Missing Positive -
Given an unsorted array, find the smallest missing positive integer. -
Jump Game -
Minimum no. of jumps required to reach the end of the array.- Article - https://www.geeksforgeeks.org/minimum-number-of-jumps-to-reach-end-of-a-given-array/ (O(n^2) DP approach)
- Article - https://www.geeksforgeeks.org/minimum-number-jumps-reach-endset-2on-solution/ (O(n) solution)
- LeetCode solution - Gave TLE. working on it. (https://leetcode.com/problems/jump-game-ii/description/)
-
SPIRAL MATRIX -
Consists of a number of questions on spiral matrix.- Article - https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/ (LeetCode 54)
- Article - https://www.geeksforgeeks.org/print-n-x-n-spiral-matrix-using-o1-extra-space/ (LeetCode 59)
-
Unique Paths -
Consists of a number of DP questions.- Article - https://www.geeksforgeeks.org/count-possible-paths-top-left-bottom-right-nxm-matrix/ (LeetCode 62)
- Article - https://www.geeksforgeeks.org/print-all-possible-paths-from-top-left-to-bottom-right-of-a-mxn-matrix/
- Article - https://www.geeksforgeeks.org/unique-paths-in-a-grid-with-obstacles/ (LeetCode 63)
-
Min Cost Path - https://www.geeksforgeeks.org/dynamic-programming-set-6-min-cost-path/ (LeetCode 64)
-
Search A 2D Matrix -
Write an efficient algorithm that searches for a value in an m x n matrix -
Set Matrix Zeroes - https://leetcode.com/problems/set-matrix-zeroes/discuss/140332/C++-in-place-solution (My leetcode solution)
-
SUBSETS -
Find all distinct subsets of a given set.- Pre-requisites - https://www.geeksforgeeks.org/power-set/
- Article - https://www.geeksforgeeks.org/find-distinct-subsets-given-set/
- LeetCode solution - https://leetcode.com/problems/subsets/ (Read https://www.geeksforgeeks.org/converting-strings-numbers-cc/ before trying to solve the LeetCode problem).
-
Merge two sorted arrays - Here are some questions related to it. (Very Imp.)
- Article - https://www.geeksforgeeks.org/merge-two-sorted-arrays/ (O(n+m) time complexity with O(n+m) space.)
- Article - https://www.geeksforgeeks.org/merge-two-sorted-arrays-o1-extra-space/ (O(mn) T.C. with O(1) space.)
- Article - https://www.geeksforgeeks.org/efficiently-merging-two-sorted-arrays-with-o1-extra-space/
- LeetCode - https://leetcode.com/problems/merge-sorted-array/
-
Remove Duplicates in Sorted Array - Here are some questions related to it.
- Article - https://www.geeksforgeeks.org/remove-duplicates-sorted-array/ (LeetCode 26)
- Article - https://www.geeksforgeeks.org/find-duplicates-in-on-time-and-constant-extra-space/
- LeetCode Question - https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/
-
Word Search - Here are some questions related to it.
-
Search an element in a rotated and sorted array - Very imp.
- Article - https://www.geeksforgeeks.org/binary-search/ (Pre-requisite)
- Article - https://www.geeksforgeeks.org/search-an-element-in-a-sorted-and-pivoted-array/ (LeetCode 33)
- LeetCode - https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ (Handling duplicates, first remove duplicates from the array in-place, and then use the above method.)
-
Largest Rectangle in histogram - Hard and important.
- Pre-requisite -
Segment Trees- https://www.geeksforgeeks.org/segment-tree-set-1-sum-of-given-range/ && https://www.geeksforgeeks.org/segment-tree-set-1-range-minimum-query/. - Article - https://www.geeksforgeeks.org/largest-rectangular-area-in-a-histogram-set-1/ (O(nlogn) solution)
- Article - https://www.geeksforgeeks.org/largest-rectangle-under-histogram/ (O(n) solution).
- LeetCode - https://leetcode.com/problems/largest-rectangle-in-histogram/description/
- Pre-requisite -
-
Trapping rainwater -
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.- Article - https://www.geeksforgeeks.org/trapping-rain-water/
- LeetCode 42 solution - https://leetcode.com/problems/trapping-rain-water/description/
-
Best Time To Buy and Sell Stock - All Cases. Refer GFG and leetcode.
-
Maximum Sum Contiguous Sub-Array - Implementation of Kadane's Algo (DP).
- Article - https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/
- LeetCode - https://leetcode.com/problems/maximum-subarray/description/ ( I have a little bit twisted solution in my leetcode one, where
max_ending_hereis being compared with nums[i], not 0, to handle the case when all the numbers in the array are negative.) - Article - https://www.geeksforgeeks.org/maximum-product-subarray/ (Maximum product subarray, a little bit different, and tough..!).
- LeetCode - https://leetcode.com/problems/maximum-product-subarray/description/ (Tweaked code, to handle all cases).
Others -
- Two Sum
- Find pairs whose sum is x
- Leaders in An Array
- Longest Palindromic Substring - DP solution
- Longest Palindromic Substring - Constant Space Solution
- Manacher's Algorithm - Linear Time Longest Palindromic Substring
- Next greater number with same set of digits
- Longest Common Prefix - Set 1, Set 2, Set 3, Set 4.
- Find the element that appears once.
- Minimum element in a rotated and sorted array
- Nth element in a set formed by two arrays
- Row with the maximum no. of 1's
- Two non-repeating elements in an array of repeating elements
- Generate n-bit binary gray codes