3247. Number of Subsequences with Odd Sum
Given an array
nums, return the number of subsequences with an odd sum of elements.Since the answer may be very large, return it modulo
109 + 7.
3247. Number of Subsequences with Odd Sum
Given an array
nums, return the number of subsequences with an odd sum of elements.Since the answer may be very large, return it modulo
109 + 7.
3284. Sum of Consecutive Subarrays
We call an array
arrof lengthnconsecutive if one of the following holds:
arr[i] - arr[i - 1] == 1for all1 <= i < n.arr[i] - arr[i - 1] == -1for all1 <= i < n.The value of an array is the sum of its elements.
For example,
[3, 4, 5]is a consecutive array of value 12 and[9, 8]is another of value 17. While[3, 4, 3]and[8, 6]are not consecutive.Given an array of integers
nums, return the sum of the values of all consecutive subarrays.Since the answer may be very large, return it modulo
109 + 7.Note that an array of length 1 is also considered consecutive.
3231. Minimum Number of Increasing Subsequence to Be Removed
Given an array of integers
nums, you are allowed to perform the following operation any number of times:
- Remove a strictly increasing subsequence from the array.
Your task is to find the minimum number of operations required to make the array empty.
3313. Find the Last Marked Nodes in Tree
There exists an undirected tree with
nnodes numbered0ton - 1. You are given a 2D integer arrayedgesof lengthn - 1, whereedges[i] = [ui, vi]indicates that there is an edge between nodesuiandviin the tree.Initially, all nodes are unmarked. After every second, you mark all unmarked nodes which have at least one marked node adjacent to them.
Return an array
nodeswherenodes[i]is the last node to get marked in the tree, if you mark nodeiat timet = 0. Ifnodes[i]has multiple answers for any nodei, you can choose any one answer.
3329. Count Substrings With K-Frequency Characters II
Given a string
sand an integerk, return the total number of substrings ofswhere at least one character appears at leastktimes.
3369. Design an Array Statistics Tracker
Design a data structure that keeps track of the values in it and answers some queries regarding their mean, median, and mode.
Implement the
StatisticsTrackerclass.
StatisticsTracker(): Initialize theStatisticsTrackerobject with an empty array.void addNumber(int number): Addnumberto the data structure.void removeFirstAddedNumber(): Remove the earliest added number from the data structure.int getMean(): Return the floored mean of the numbers in the data structure.int getMedian(): Return the median of the numbers in the data structure.int getMode(): Return the mode of the numbers in the data structure. If there are multiple modes, return the smallest one.Note:
- The mean of an array is the sum of all the values divided by the number of values in the array.
- The median of an array is the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the larger of the two values is taken.
- The mode of an array is the element that appears most often in the array.
3383. Minimum Runes to Add to Cast Spell
Alice has just graduated from wizard school, and wishes to cast a magic spell to celebrate. The magic spell contains certain focus points where magic needs to be concentrated, and some of these focus points contain magic crystals which serve as the spell’s energy source. Focus points can be linked through directed runes, which channel magic flow from one focus point to another.
You are given a integer
ndenoting the number of focus points and an array of integerscrystalswherecrystals[i]indicates a focus point which holds a magic crystal. You are also given two integer arraysflowFromandflowTo, which represent the existing directed runes. Theithrune allows magic to freely flow from focus pointflowFrom[i]to focus pointflowTo[i].You need to find the number of directed runes Alice must add to her spell, such that each focus point either:
- Contains a magic crystal.
- Receives magic flow from another focus point.
Return the minimum number of directed runes that she should add.
3385. Minimum Time to Break Locks II
Bob is stuck in a dungeon and must break
nlocks, each requiring some amount of energy to break. The required energy for each lock is stored in an array calledstrengthwherestrength[i]indicates the energy needed to break theithlock.To break a lock, Bob uses a sword with the following characteristics:
- The initial energy of the sword is 0.
- The initial factor
Xby which the energy of the sword increases is 1.- Every minute, the energy of the sword increases by the current factor
X.- To break the
ithlock, the energy of the sword must reach at leaststrength[i].- After breaking a lock, the energy of the sword resets to 0, and the factor
Xincreases by 1.Your task is to determine the minimum time in minutes required for Bob to break all
nlocks and escape the dungeon.Return the minimum time required for Bob to break all
nlocks.
3406. Find the Lexicographically Largest String From the Box II
You are given a string
word, and an integernumFriends.Alice is organizing a game for her
numFriendsfriends. There are multiple rounds in the game, where in each round:
wordis split intonumFriendsnon-empty strings, such that no previous round has had the exact same split.- All the split words are put into a box.
Find the lexicographically largest string from the box after all the rounds are finished.
A string
ais lexicographically smaller than a stringbif in the first position whereaandbdiffer, stringahas a letter that appears earlier in the alphabet than the corresponding letter inb.
If the firstmin(a.length, b.length)characters do not differ, then the shorter string is the lexicographically smaller one.
3735. Lexicographically Smallest String After Reverse II
You are given a string
sof lengthnconsisting of lowercase English letters.You must perform exactly one operation by choosing any integer
ksuch that1 <= k <= nand either:
- reverse the first
kcharacters ofs, or- reverse the last
kcharacters ofs.Return the lexicographically smallest string that can be obtained after exactly one such operation.