The setContinue reading “[Leetcode problems]60. Permutation Sequence”`[1,2,3,...,`

contains a total ofn]n! unique permutations. By listing and labeling all of the permutations in order, we get the following sequence forn= 3:`"123";"132"`

;`"213"`

;`"231"`

;`"312"`

;`"321"`

Givennandk, return thek^{t}^{h}permutation sequence.Note:Givennwill be between 1 and 9 inclusive. Givenkwill be between 1 andn! inclusive.Example 1:Input:n = 3, k = 3Output:"213"

## [Leetcode problems]75. Sort Colors

Given an array withContinue reading “[Leetcode problems]75. Sort Colors”nobjects colored red, white or blue, sort themin-placeso that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.Note:You are not suppose to use the library's sort function for this problem.Example:Input:[2,0,2,1,1,0]Output:[0,0,1,1,2,2]

## [Leetcode problems]1482. Minimum Number of Days to Make m Bouquets

Given an integer arrayContinue reading “[Leetcode problems]1482. Minimum Number of Days to Make m Bouquets”`bloomDay`

, an integer`m`

and an integer`k`

. We need to make`m`

bouquets. To make a bouquet, you need to use`k`

adjacent flowersfrom the garden. The garden consists of`n`

flowers, the`ith`

flower will bloom in the`bloomDay[i]`

and then can be used inexactly onebouquet. Returnthe minimum number of daysyou need to wait to be able to make`m`

bouquets from the garden. If it is impossible to make`m`

bouquets return-1.Example 1:Input:bloomDay = [1,10,3,10,2], m = 3, k = 1Output:3Explanation:Let's see what happened in the first three days. x means flower bloomed and _ means flower didn't bloom in the garden. We need 3 bouquets each should contain 1 flower. After day 1: [x, _, _, _, _] // we can only make one bouquet. After day 2: [x, _, _, _, x] // we can only make two bouquets. After day 3: [x, _, x, _, x] // we can make 3 bouquets. The answer is 3.

## [Leetcode problems]1477. Find Two Non-overlapping Sub-arrays Each With Target Sum

Given an array of integersContinue reading “[Leetcode problems]1477. Find Two Non-overlapping Sub-arrays Each With Target Sum”`arr`

and an integer`target`

. You have to findtwo non-overlapping sub-arraysof`arr`

each with sum equal`target`

. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays isminimum. Returnthe minimum sum of the lengthsof the two required sub-arrays, or returnif you cannot find such two sub-arrays.-1Example 1:Input:arr = [3,2,2,4,3], target = 3Output:2Explanation:Only two sub-arrays have sum = 3 ([3] and [3]). The sum of their lengths is 2.Example 2:Input:arr = [7,3,4,7], target = 7Output:2Explanation:Although we have three non-overlapping sub-arrays of sum = 7 ([7], [3,4] and [7]), but we will choose the first and third sub-arrays as the sum of their lengths is 2.

## [Leetcode Problems]240. Search a 2D Matrix II

Write an efficient algorithm that searches for a value in anContinue reading “[Leetcode Problems]240. Search a 2D Matrix II”mxnmatrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each column are sorted in ascending from top to bottom.Example:Consider the following matrix: [ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19], [3, 6, 9, 16, 22], [10, 13, 14, 17, 24], [18, 21, 23, 26, 30] ] Given target =`5`

, return`true`

. Given target =`20`

, return`false`

.

## [Leetcode]1008. Construct Binary Search Tree from Preorder Traversal

Question: Given a preorder traversal, reconstruct the binary search tree and return the root. Input:Continue reading “[Leetcode]1008. Construct Binary Search Tree from Preorder Traversal”`[8,5,1,7,10,12]`

Output:`[8,5,10,1,7,null,12]`

Visiualization of the output: