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]1. Two Sum

Given an array of integers, returnContinue reading “[Leetcode]1. Two Sum”indicesof the two numbers such that they add up to a specific target. You may assume that each input would haveone solution, and you may not use theexactlysameelement twice.Example:Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0,1].

## [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]

## [Leetcode]1497. Check If Array Pairs Are Divisible by k

Given an array of integersContinue reading “[Leetcode]1497. Check If Array Pairs Are Divisible by k”`arr`

of even length`n`

and an integer`k`

. We want to divide the array into exactly`n / 2`

pairs such that the sum of each pair is divisible by`k`

. ReturnTrueIf you can find a way to do that orFalseotherwise.Example 1:Input:arr = [1,2,3,4,5,10,6,7,8,9], k = 5Output:trueExplanation:Pairs are (1,9),(2,8),(3,7),(4,6) and (5,10).

## Floyd’s Cycle Detection Algorithm – [Leetcode]142. Linked List Cycle II

The cycle detection problem is to find the cycle in a sequence, and Floyd’s cycle detection algorithm, aka Tortoise and Hare algorithm, is a two pointers algorithm to detect the cycle and the start of the cycle as well.

Continue reading “Floyd’s Cycle Detection Algorithm – [Leetcode]142. Linked List Cycle II”## [Leetcode]957. Prison Cells After N Days

There are 8 prison cells in a row, and each cell is either occupied or vacant. Each day, whether the cell is occupied or vacant changes according to the following rules: 1. If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied. 2. Otherwise, it becomes vacant. (Note that because the prison is a row, the first and the last cells in the row can't have two adjacent neighbors.) We describe the current state of the prison in the following way:Continue reading “[Leetcode]957. Prison Cells After N Days”`cells[i] == 1`

if the`i`

-th cell is occupied, else`cells[i] == 0`

. Given the initial state of the prison, return the state of the prison after`N`

days (and`N`

such changes described above.)

## [Leetcode]212. Word Search II

Given a 2D board and a list of words from the dictionary, find all words in the board. Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.Continue reading “[Leetcode]212. Word Search II”Example:Input:board= [ ['o','a','a','n'], ['e','t','a','e'], ['i','h','k','r'], ['i','f','l','v'] ]words=`["oath","pea","eat","rain"]`

Output:`["eat","oath"]`

## Intro to Trie (Prefix Tree) – FEAT. Leetcode 208. Implement Trie

A trie, or a prefix tree, refers to an ordered data structure that is usually used to store strings (Wikipedia). The picture on the above is an example where a trie stores `[ape,apple,are,art]`

. Now let’s take a closer look at it and it’s not hard to find that: