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 by
p. It is not allowed to remove the whole array. Return the length of the smallest subarray that you need to remove, or
-1if it's impossible. A subarray is defined as a contiguous block of elements in the array.
You are given an integer arrayContinue reading “[Leetcode]33. Search in Rotated Sorted Array”
numssorted in ascending order, and an integer
target. Suppose that
numsis rotated at some pivot unknown to you beforehand (i.e.,
targetis found in the array return its index, otherwise, return
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”
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
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
Solve a given equation and return the value ofContinue reading “[Leetcode]640. Solve the Equation”
xin the form of string "x=#value". The equation contains only '+', '-' operation, the variable
xand 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
xis an integer.
Given a string that contains only digitsContinue reading “[Leetcode]282. Expression Add Operators”
0-9and a target value, return all possibilities to add binaryoperators (not unary)
*between the digits so they evaluate to the target value.
Your task is to form an integer arrayContinue reading “[Leetcode]1558. Minimum Numbers of Function Calls to Make Target Array”
numsfrom an initial array of zeros
arrthat is the same size as
nums. Return the minimum number of function calls to make
arr. The answer is guaranteed to fit in a 32-bit signed integer.