2638. Count the Number of K-Free Subsets
You are given an integer array
nums, which contains distinct elements and an integerk.A subset is called a k-Free subset if it contains no two elements with an absolute difference equal to
k. Notice that the empty set is a k-Free subset.Return the number of k-Free subsets of
nums.A subset of an array is a selection of elements (possibly none) of the array.
2640. Find the Score of All Prefixes of an Array
We define the conversion array
converof an arrayarras follows:
conver[i] = arr[i] + max(arr[0..i])wheremax(arr[0..i])is the maximum value ofarr[j]over0 <= j <= i.We also define the score of an array
arras the sum of the values of the conversion array ofarr.Given a 0-indexed integer array
numsof lengthn, return an arrayansof lengthnwhereans[i]is the score of the prefixnums[0..i].
2641. Cousins in Binary Tree II
Given the
rootof a binary tree, replace the value of each node in the tree with the sum of all its cousins’ values.Two nodes of a binary tree are cousins if they have the same depth with different parents.
Return the
rootof the modified tree.Note that the depth of a node is the number of edges in the path from the root node to it.
2655. Find Maximal Uncovered Ranges
You are given an integer
nwhich is the length of a 0-indexed arraynums, and a 0-indexed 2D-arrayranges, which is a list of sub-ranges ofnums(sub-ranges may overlap).Each row
ranges[i]has exactly 2 cells:
ranges[i][0], which shows the start of the ith range (inclusive)ranges[i][1], which shows the end of the ith range (inclusive)These ranges cover some cells of
numsand leave some cells uncovered. Your task is to find all of the uncovered ranges with maximal length.Return a 2D-array
answerof the uncovered ranges, sorted by the starting point in ascending order.By all of the uncovered ranges with maximal length, we mean satisfying two conditions:
- Each uncovered cell should belong to exactly one sub-range
- There should not exist two ranges (l1, r1) and (l2, r2) such that r1 + 1 = l2
2642. Design Graph With Shortest Path Calculator
There is a directed weighted graph that consists of
nnodes numbered from0ton - 1. The edges of the graph are initially represented by the given arrayedgeswhereedges[i] = [fromi, toi, edgeCosti]meaning that there is an edge fromfromitotoiwith the costedgeCosti.Implement the
Graphclass:
Graph(int n, int[][] edges)initializes the object withnnodes and the given edges.addEdge(int[] edge)adds an edge to the list of edges whereedge = [from, to, edgeCost]. It is guaranteed that there is no edge between the two nodes before adding this one.int shortestPath(int node1, int node2)returns the minimum cost of a path fromnode1tonode2. If no path exists, return-1. The cost of a path is the sum of the costs of the edges in the path.
You are given an integer
n. Consider an equilateral triangle of side lengthn, broken up inton2unit equilateral triangles. The triangle hasnithrow has2i - 1unit equilateral triangles.The triangles in the
ith``(i, 1)to(i, 2i - 1). The following image shows a triangle of side length4with the indexing of its triangle.
Two triangles are neighbors if they share a side. For example:
- Triangles
(1,1)and(2,2)are neighbors- Triangles
(3,2)and(3,3)are neighbors.- Triangles
(2,2)and(3,3)are not neighbors because they do not share any side.
1 >k
- If there is no such triangle, stop the algorithm.
- Color that triangle red.
- Go to step 1.
Choose the minimum
kpossible and setktriangles red before running this algorithm such that after the algorithm stops, all unit triangles are colored red.Return a 2D list of the coordinates of the triangles that you will color red initially. The answer has to be of the smallest size possible. If there are multiple valid solutions, return any.