Given an integer arrayContinue reading “[Leetcode]1574. Shortest Subarray to be Removed to Make Array Sorted”arr
, remove a subarray (can be empty) fromarr
such that the remaining elements inarr
are non-decreasing. A subarray is a contiguous subsequence of the array. Return the length of the shortest subarray to remove.
[Leetcode]340. Longest Substring with At Most K Distinct Characters
Given a string, find the length of the longest substring T that contains at most k distinct characters.Continue reading “[Leetcode]340. Longest Substring with At Most K Distinct Characters”
[Leetcode]283. Move Zeroes
Given an arrayContinue reading “[Leetcode]283. Move Zeroes”nums
, write a function to move all0
's to the end of it while maintaining the relative order of the non-zero elements. Note: You must do this in-place without making a copy of the array. Minimize the total number of operations.
[Leetcode]1537. Get the Maximum Score
You are given two sorted arrays of distinct integersContinue reading “[Leetcode]1537. Get the Maximum Score”nums1
andnums2.
A valid path is defined as follows: Choose array nums1 or nums2 to traverse (from index-0). Traverse the current array from left to right. If you are reading any value that is present innums1
andnums2
you are allowed to change your path to the other array. (Only one repeated value is considered in the valid path). Score is defined as the sum of uniques values in a valid path. Return the maximum score you can obtain of all possible valid paths. Since the answer may be too large, return it modulo 10^9 + 7.
[Leetcode]42. Trapping Rain Water
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. Example: Input: height=[0,1,0,2,1,0,1,3,2,1,2,1] Output: 6Continue reading “[Leetcode]42. Trapping Rain Water”
[Leetcode]18. 4Sum
Given an arrayContinue reading “[Leetcode]18. 4Sum”nums
of n integers and an integertarget
, are there elements a, b, c, and d innums
such that a + b + c + d =target
? Find all unique quadruplets in the array which gives the sum oftarget
. Note: The solution set must not contain duplicate quadruplets. Example: Given array nums = [1, 0, -1, 0, -2, 2], and target = 0. A solution set is: [ [-1, 0, 0, 1], [-2, -1, 1, 2], [-2, 0, 0, 2] ]
[Leetcode]15. 3Sum
Given an arrayContinue reading “[Leetcode]15. 3Sum”nums
of n integers, are there elements a, b, c innums
such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: The solution set must not contain duplicate triplets. Example: Given array nums = [-1, 0, 1, 2, -1, -4], A solution set is: [ [-1, 0, 1], [-1, -1, 2] ]
[Leetcode]1498. Number of Subsequences That Satisfy the Given Sum Condition
Given an array of integersContinue reading “[Leetcode]1498. Number of Subsequences That Satisfy the Given Sum Condition”nums
and an integertarget
. Return the number of non-empty subsequences ofnums
such that the sum of the minimum and maximum element on it is less or equal thantarget
. Since the answer may be too large, return it modulo 10^9 + 7. Input: nums = [3,3,6,8], target = 10 Output: 6 Explanation: There are 6 subsequences that satisfy the condition. (nums can have repeated numbers). [3] , [3] , [3,3], [3,6] , [3,6] , [3,3,6]