There exists an undirected and unrooted tree with
nnodes indexed from0ton - 1. You are given an integernand a 2D integer array edges of lengthn - 1, whereedges[i] = [ai, bi]indicates that there is an edge between nodesaiandbiin the tree. You are also given an arraycoinsof sizenwherecoins[i]can be either0or1, where1indicates the presence of a coin in the vertexi.Initially, you choose to start at any vertex in the tree. Then, you can perform the following operations any number of times:
- Collect all the coins that are at a distance of at most
2from the current vertex, or- Move to any adjacent vertex in the tree.
Find the minimum number of edges you need to go through to collect all the coins and go back to the initial vertex.
Note that if you pass an edge several times, you need to count it into the answer several times.
2602. Minimum Operations to Make All Array Elements Equal
You are given an array
numsconsisting of positive integers.You are also given an integer array
queriesof sizem. For theithquery, you want to make all of the elements ofnumsequal toqueries[i]. You can perform the following operation on the array any number of times:
- Increase or decrease an element of the array by
1.Return an array
answerof sizemwhereanswer[i]is the minimum number of operations to make all elements ofnumsequal toqueries[i].Note that after each query the array is reset to its original state.
2601. Prime Subtraction Operation
You are given a 0-indexed integer array
numsof lengthn.You can perform the following operation as many times as you want:
- Pick an index
ithat you haven’t picked before, and pick a primepstrictly less thannums[i], then subtractpfromnums[i].Return true if you can make
numsa strictly increasing array using the above operation and false otherwise.A strictly increasing array is an array whose each element is strictly greater than its preceding element.
2600. K Items With the Maximum Sum
There is a bag that consists of items, each item has a number
1,0, or-1written on it.You are given four non-negative integers
numOnes,numZeros,numNegOnes, andk.The bag initially contains:
numOnesitems with1s written on them.numZeroesitems with0s written on them.numNegOnesitems with-1s written on them.We want to pick exactly
kitems among the available items. Return the maximum possible sum of numbers written on the items.