3251. Find the Count of Monotonic Pairs II
You are given an array of positive integers
nums
of lengthn
.We call a pair of non-negative integer arrays
(arr1, arr2)
monotonic if:
- The lengths of both arrays are
n
.arr1
is monotonically non-decreasing, in other words,arr1[0] <= arr1[1] <= ... <= arr1[n - 1]
.arr2
is monotonically non-increasing, in other words,arr2[0] >= arr2[1] >= ... >= arr2[n - 1]
.arr1[i] + arr2[i] == nums[i]
for all0 <= i <= n - 1
.Return the count of monotonic pairs.
Since the answer may be very large, return it modulo
109 + 7
.
3250. Find the Count of Monotonic Pairs I
You are given an array of positive integers
nums
of lengthn
.We call a pair of non-negative integer arrays
(arr1, arr2)
monotonic if:
- The lengths of both arrays are
n
.arr1
is monotonically non-decreasing, in other words,arr1[0] <= arr1[1] <= ... <= arr1[n - 1]
.arr2
is monotonically non-increasing, in other words,arr2[0] >= arr2[1] >= ... >= arr2[n - 1]
.arr1[i] + arr2[i] == nums[i]
for all0 <= i <= n - 1
.Return the count of monotonic pairs.
Since the answer may be very large, return it modulo
109 + 7
.
3249. Count the Number of Good Nodes
There is an undirected tree with
n
nodes labeled from0
ton - 1
, and rooted at node0
. You are given a 2D integer arrayedges
of lengthn - 1
, whereedges[i] = [ai, bi]
indicates that there is an edge between nodesai
andbi
in the tree.A node is good if all the subtrees rooted at its children have the same size.
Return the number of good nodes in the given tree.
A subtree of
treeName
is a tree consisting of a node intreeName
and all of its descendants.
There is a snake in an
n x n
matrixgrid
and can move in four possible directions. Each cell in thegrid
is identified by the position:grid[i][j] = (i * n) + j
.The snake starts at cell 0 and follows a sequence of commands.
You are given an integer
n
representing the size of thegrid
and an array of stringscommands
where eachcommand[i]
is either"UP"
,"RIGHT"
,"DOWN"
, and"LEFT"
. It’s guaranteed that the snake will remain within thegrid
boundaries throughout its movement.Return the position of the final cell where the snake ends up after executing
commands
.