Given an integer arrayContinue reading “[Leetcode]1574. Shortest Subarray to be Removed to Make Array Sorted”`arr`

, remove a subarray (can be empty) from`arr`

such that the remaining elements in`arr`

arenon-decreasing. A subarray is a contiguous subsequence of the array. Returnthe 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 mostContinue reading “[Leetcode]340. Longest Substring with At Most K Distinct Characters”kdistinct characters.

## [Leetcode]283. Move Zeroes

Given an arrayContinue reading “[Leetcode]283. Move Zeroes”`nums`

, write a function to move all`0`

's to the end of it while maintaining the relative order of the non-zero elements.Note: You must do thisin-placewithout making a copy of the array. Minimize the total number of operations.

## [Leetcode]1537. Get the Maximum Score

You are given twoContinue reading “[Leetcode]1537. Get the Maximum Score”sortedarrays of distinct integers`nums1`

and`nums2.`

Avalidis 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 inpath`nums1`

and`nums2`

you are allowed to change your path to the other array. (Only one repeated value is considered in the valid path).Scoreis defined as the sum of uniques values in a valid path. Return the maximumscoreyou can obtain of all possiblevalid paths. Since the answer may be too large, return it modulo 10^9 + 7.

## [Leetcode]42. Trapping Rain Water

GivenContinue reading “[Leetcode]42. Trapping Rain Water”nnon-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:6

## [Leetcode]18. 4Sum

Given an arrayContinue reading “[Leetcode]18. 4Sum”`nums`

ofnintegers and an integer`target`

, are there elementsa,b,c, anddin`nums`

such thata+b+c+d=`target`

? Find all unique quadruplets in the array which gives the sum of`target`

.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`

ofnintegers, are there elementsa,b,cin`nums`

such thata+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 integer`target`

. Return the number ofnon-emptysubsequences of`nums`

such that the sum of the minimum and maximum element on it is less or equal than`target`

. Since the answer may be too large, return it modulo 10^9 + 7.Input:nums = [3,3,6,8], target = 10Output:6Explanation:There are 6 subsequences that satisfy the condition. (nums can have repeated numbers). [3] , [3] , [3,3], [3,6] , [3,6] , [3,3,6]