3026. Maximum Good Subarray Sum
You are given an array
numsof lengthnand a positive integerk.A subarray of
numsis called good if the absolute difference between its first and last element is exactlyk, in other words, the subarraynums[i..j]is good if|nums[i] - nums[j]| == k.Return the maximum sum of a good subarray of
nums. If there are no good subarrays**, return0.
3027. Find the Number of Ways to Place People II
You are given a 2D array
pointsof sizen x 2representing integer coordinates of some points on a 2D-plane, wherepoints[i] = [xi, yi].We define the right direction as positive x-axis (increasing x-coordinate) and the left direction as negative x-axis (decreasing x-coordinate). Similarly, we define the up direction as positive y-axis (increasing y-coordinate) and the down direction as negative y-axis (decreasing y-coordinate)
You have to place
npeople, including Chisato and Takina, at these points such that there is exactly one person at every point. Chisato wants to be alone with Takina, so Chisato will build a rectangular fence with Chisato’s position as the upper left corner and Takina’s position as the lower right corner of the fence (Note that the fence might not enclose any area, i.e. it can be a line). If any person other than Chisato and Takina is either inside the fence or on the fence, Chisato will be sad.Return the number of pairs of points where you can place Chisato and Takina, such that Chisato does not become sad on building the fence.
Note that Chisato can only build a fence with Chisato’s position as the upper left corner, and Takina’s position as the lower right corner. For example, Chisato cannot build either of the fences in the picture below with four corners
(1, 1),(1, 3),(3, 1), and(3, 3), because:
- With Chisato at
(3, 3)and Takina at(1, 1), Chisato’s position is not the upper left corner and Takina’s position is not the lower right corner of the fence.- With Chisato at
(1, 3)and Takina at(1, 1), Takina’s position is not the lower right corner of the fence.
3025. Find the Number of Ways to Place People I
You are given a 2D array
pointsof sizen x 2representing integer coordinates of some points on a 2D-plane, wherepoints[i] = [xi, yi].We define the right direction as positive x-axis (increasing x-coordinate) and the left direction as negative x-axis (decreasing x-coordinate). Similarly, we define the up direction as positive y-axis (increasing y-coordinate) and the down direction as negative y-axis (decreasing y-coordinate)
You have to place
npeople, including Chisato and Takina, at these points such that there is exactly one person at every point. Chisato wants to be alone with Takina, so Chisato will build a rectangular fence with Chisato’s position as the upper left corner and Takina’s position as the lower right corner of the fence (Note that the fence might not enclose any area, i.e. it can be a line). If any person other than Chisato and Takina is either inside the fence or on the fence, Chisato will be sad.Return the number of pairs of points where you can place Chisato and Takina, such that Chisato does not become sad on building the fence.
Note that Chisato can only build a fence with Chisato’s position as the upper left corner, and Takina’s position as the lower right corner. For example, Chisato cannot build either of the fences in the picture below with four corners
(1, 1),(1, 3),(3, 1), and(3, 3), because:
- With Chisato at
(3, 3)and Takina at(1, 1), Chisato’s position is not the upper left corner and Takina’s position is not the lower right corner of the fence.- With Chisato at
(1, 3)and Takina at(1, 1), Takina’s position is not the lower right corner of the fence.
You are given a 0-indexed integer array
numsof size3which can form the sides of a triangle.
- A triangle is called equilateral if it has all sides of equal length.
- A triangle is called isosceles if it has exactly two sides of equal length.
- A triangle is called scalene if all its sides are of different lengths.
Return a string representing the type of triangle that can be formed or
"none"if it cannot form a triangle.
Given a binary array
nums, return the maximum number of consecutive1‘s in the array.
3023. Find Pattern in Infinite Stream I
You are given a binary array
patternand an objectstreamof classInfiniteStreamrepresenting a 0-indexed infinite stream of bits.The class
InfiniteStreamcontains the following function:
int next(): Reads a single bit (which is either0or1) from the stream and returns it.Return the first starting index where the pattern matches the bits read from the stream. For example, if the pattern is
[1, 0], the first match is the highlighted part in the stream[0, **1, 0**, 1, ...].
3004. Maximum Subtree of the Same Color
You are given a 2D integer array
edgesrepresenting a tree withnnodes, numbered from0ton - 1, rooted at node0, whereedges[i] = [ui, vi]means there is an edge between the nodesviandui.You are also given a 0-indexed integer array
colorsof sizen, wherecolors[i]is the color assigned to nodei.We want to find a node
vsuch that every node in the subtree ofvhas the same color.Return the size of such subtree with the maximum number of nodes possible.
2955. Number of Same-End Substrings
You are given a 0-indexed string
s, and a 2D array of integersqueries, wherequeries[i] = [li, ri]indicates a substring ofsstarting from the indexliand ending at the indexri(both inclusive), i.e.s[li..ri].Return an array
answhereans[i]is the number of same-end substrings ofqueries[i].A 0-indexed string
tof lengthnis called same-end if it has the same character at both of its ends, i.e.,t[0] == t[n - 1].A substring is a contiguous non-empty sequence of characters within a string.
564. Find the Closest Palindrome
Given a string
nrepresenting an integer, return the closest integer (not including itself), which is a palindrome. If there is a tie, return the smaller one.The closest is defined as the absolute difference minimized between two integers.