Given an array of positive integersContinue reading “[Leetcode]1590. Make Sum Divisible by P”`nums`

, remove thesmallestsubarray (possiblyempty) such that thesumof the remaining elements is divisible by`p`

. It isnotallowed to remove the whole array. Returnthe length of the smallest subarray that you need to remove, or`-1`

if it's impossible. Asubarrayis defined as a contiguous block of elements in the array.

### [Leetcode]33. Search in Rotated Sorted Array

You are given an integer arrayContinue reading “[Leetcode]33. Search in Rotated Sorted Array”`nums`

sorted in ascending order, and an integer`target`

. Suppose that`nums`

is rotated at some pivot unknown to you beforehand (i.e.,`[0,1,2,4,5,6,7]`

might become`[4,5,6,7,0,1,2]`

).If`target`

is found in the array return its index, otherwise, return`-1`

.

### [Leetcode]421. Maximum XOR of Two Numbers in an Array

Given aContinue reading “[Leetcode]421. Maximum XOR of Two Numbers in an Array”non-emptyarray of numbers, a_{0}, a_{1}, a_{2}, … , a_{n-1}, where 0 ≤ a_{i}< 2^{31}. Find the maximum result of a_{i}XOR a_{j}, where 0 ≤i,j<n. Could you do this in O(n) runtime?

### Disjoint Set – Union & Find

Continue reading “Disjoint Set – Union & Find”In computer science, a

Source: https://en.wikipedia.org/wiki/Disjoint-set_data_structuredisjoint-set data structure… is a data structure that stores a collection of disjoint (non-overlapping) sets. … It provides operations for adding new sets, merging sets (replacing them by their union), and finding a representative member of a set.

### Minimum Spanning Tree – Prim

Continue reading “Minimum Spanning Tree – Prim”A

Source: https://en.wikipedia.org/wiki/Minimum_spanning_treeminimum spanning tree(MST) orminimum weight spanning treeis a subset of the edges of a connected, edge-weighted undirected graph that connects all the vertices together, without any cycles and with the minimum possible total edge weight.

### [Leetcode]640. Solve the Equation

Solve a given equation and return the value ofContinue reading “[Leetcode]640. Solve the Equation”`x`

in the form of string "x=#value". The equation contains only '+', '-' operation, the variable`x`

and its coefficient. If there is no solution for the equation, return "No solution". If there are infinite solutions for the equation, return "Infinite solutions". If there is exactly one solution for the equation, we ensure that the value of`x`

is an integer.

### [Leetcode]282. Expression Add Operators

Given a string that contains only digitsContinue reading “[Leetcode]282. Expression Add Operators”`0-9`

and a target value, return all possibilities to addbinaryoperators (not unary)`+`

,`-`

, or`*`

between the digits so they evaluate to the target value.

### [Leetcode]1558. Minimum Numbers of Function Calls to Make Target Array

Your task is to form an integer arrayContinue reading “[Leetcode]1558. Minimum Numbers of Function Calls to Make Target Array”`nums`

from an initial array of zeros`arr`

that is the same size as`nums`

. Return the minimum number of function calls to make`nums`

from`arr`

. The answer is guaranteed to fit in a 32-bit signed integer.