Given an array of positive integersContinue reading “[Leetcode]1590. Make Sum Divisible by P”nums
, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible byp
. It is not allowed to remove the whole array. Return the length of the smallest subarray that you need to remove, or-1
if it's impossible. A subarray is 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 integertarget
. Suppose thatnums
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]
). Iftarget
is found in the array return its index, otherwise, return-1
.
[Leetcode]421. Maximum XOR of Two Numbers in an Array
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum result of ai XOR aj, where 0 ≤ i, j < n. Could you do this in O(n) runtime?Continue reading “[Leetcode]421. Maximum XOR of Two Numbers in an Array”
Disjoint Set – Union & Find
Continue reading “Disjoint Set – Union & Find”In computer science, a disjoint-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.
Source: https://en.wikipedia.org/wiki/Disjoint-set_data_structure
Minimum Spanning Tree – Prim
Continue reading “Minimum Spanning Tree – Prim”A minimum spanning tree (MST) or minimum weight spanning tree is 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.
Source: https://en.wikipedia.org/wiki/Minimum_spanning_tree
[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 variablex
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 ofx
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 add binaryoperators (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 zerosarr
that is the same size asnums
. Return the minimum number of function calls to makenums
fromarr
. The answer is guaranteed to fit in a 32-bit signed integer.