SYSuraj Yadavinsuraj26.hashnode.dev·Dec 11, 2021 · 2 min read3 Sum - LeetCodeThe problem is taken from 15. 3Sum. Naive Approach Naive approach would be to go through all possible triplets in the array. And use set data structure to remove duplicates. Code - class Solution { public: vector<vector<int>> threeSum(vector<i...00
SYSuraj Yadavinsuraj26.hashnode.dev·Dec 6, 2021 · 1 min readPascal's Triangle - LeetCodeThe problem is taken from 118. Pascal's Triangle. Approach Let's make a pascal's triangle of size 5. 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 We could see that the very first and the very last eleme...00
SYSuraj Yadavinsuraj26.hashnode.dev·Dec 5, 2021 · 2 min readMerge Sorted Array - LeetCodeThe problem is taken from 88. Merge Sorted Array. Naive approach In this approach, we use a HashMap(Integer, Integer), where the first place would hold numbers in the array and second place would hold their occurrences. Code - class Solution { pu...00
SYSuraj Yadavinsuraj26.hashnode.dev·Dec 4, 2021 · 3 min readMaximum Sum Contiguous Subarray - LeetCodeThe problem is taken from 53. Maximum Subarray. Brute force approach For each element in the array we need to find all possible contiguous subarray to the right of it. Code - class Solution { public: int maxSubArray(vector<int>& nums) { ...00
SYSuraj Yadavinsuraj26.hashnode.dev·Dec 2, 2021 · 2 min readSearch Insert Position - LeetCodeThe problem is taken from 35. Search Insert Position. Approach The solution is very straight forward. We need to do binary search on the given array and try to find the target value. But the catch here is, if the target value is not found in the arr...00