3327. Check if DFS Strings Are Palindromes
You are given a tree rooted at node 0, consisting of
nnodes numbered from0ton - 1. The tree is represented by an arrayparentof sizen, whereparent[i]is the parent of nodei. Since node 0 is the root,parent[0] == -1.You are also given a string
sof lengthn, wheres[i]is the character assigned to nodei.Consider an empty string
dfsStr, and define a recursive functiondfs(int x)that takes a nodexas a parameter and performs the following steps in order:
- Iterate over each child
yofxin increasing order of their numbers, and calldfs(y).- Add the character
s[x]to the end of the stringdfsStr.Note that
dfsStris shared across all recursive calls ofdfs.You need to find a boolean array
answerof sizen, where for each indexifrom0ton - 1, you do the following:
- Empty the string
dfsStrand calldfs(i).- If the resulting string
dfsStris a palindrome, then setanswer[i]totrue. Otherwise, setanswer[i]tofalse.Return the array
answer.A palindrome is a string that reads the same forward and backward.
3326. Minimum Division Operations to Make Array Non Decreasing
You are given an integer array
nums.Any positive divisor of a natural number
xthat is strictly less thanxis called a proper divisor ofx. For example, 2 is a proper divisor of 4, while 6 is not a proper divisor of 6.You are allowed to perform an operation any number of times on
nums, where in each operation you select any one element fromnumsand divide it by its greatest proper divisor.Return the minimum number of operations required to make the array non-decreasing.
If it is not possible to make the array non-decreasing using any number of operations, return
-1.
3325. Count Substrings With K-Frequency Characters I
Given a string
sand an integerk, return the total number of substrings ofswhere at least one character appears at leastktimes.A substring is a contiguous non-empty sequence of characters within a string.
3324. Find the Sequence of Strings Appeared on the Screen
You are given a string
target.Alice is going to type
targeton her computer using a special keyboard that has only two keys:
- Key 1 appends the character
"a"to the string on the screen.- Key 2 changes the last character of the string on the screen to its next character in the English alphabet. For example,
"c"changes to"d"and"z"changes to"a".Note that initially there is an empty string
""on the screen, so she can only press key 1.Return a list of all strings that appear on the screen as Alice types
target, in the order they appear, using the minimum key presses.
3323. Minimize Connected Groups by Inserting Interval
You are given a 2D array
intervals, whereintervals[i] = [starti, endi]represents the start and the end of intervali. You are also given an integerk.You must add exactly one new interval
[startnew, endnew]to the array such that:
- The length of the new interval,
endnew - startnew, is at mostk.- After adding, the number of connected groups in
intervalsis minimized.A connected group of intervals is a maximal collection of intervals that, when considered together, cover a continuous range from the smallest point to the largest point with no gaps between them. Here are some examples:
- A group of intervals
[[1, 2], [2, 5], [3, 3]]is connected because together they cover the range from 1 to 5 without any gaps.- However, a group of intervals
[[1, 2], [3, 4]]is not connected because the segment(2, 3)is not covered.Return the minimum number of connected groups after adding exactly one new interval to the array.