10034. Number of Possible Sets of Closing Branches
There is a company with
nbranches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, they have decided to close down some of these branches (possibly none). However, they want to ensure that the remaining branches have a distance of at most
maxDistancefrom each other.The distance between two branches is the minimum total traveled length needed to reach one branch from another.
You are given integers
n,maxDistance, and a 0-indexed 2D arrayroads, whereroads[i] = [ui, vi, wi]represents the undirected road between branchesuiandviwith lengthwi.Return the number of possible sets of closing branches, so that any branch has a distance of at most
maxDistancefrom any other.Note that, after closing a branch, the company will no longer have access to any roads connected to it.
Note that, multiple roads are allowed.
10033. Length of Longest Subarray With at Most K Frequency
You are given an integer array
numsand an integerk.The frequency of an element
xis the number of times it occurs in an array.An array is called good if the frequency of each element in this array is less than or equal to
k.Return the length of the longest good subarray of
nums.A subarray is a contiguous non-empty sequence of elements within an array.
10032. Remove Adjacent Almost-Equal Characters
You are given a 0-indexed string
word.In one operation, you can pick any index
iofwordand changeword[i]to any lowercase English letter.Return the minimum number of operations needed to remove all adjacent almost-equal characters from
word.Two characters
aandbare almost-equal ifa == boraandbare adjacent in the alphabet.
10031. Find Common Elements Between Two Arrays
You are given two 0-indexed integer arrays
nums1andnums2of sizesnandm, respectively.Consider calculating the following values:
- The number of indices
isuch that0 <= i < nandnums1[i]occurs at least once innums2.- The number of indices
isuch that0 <= i < mandnums2[i]occurs at least once innums1.Return an integer array
answerof size2containing the two values in the above order.