3251. Find the Count of Monotonic Pairs II
You are given an array of positive integers
numsof lengthn.We call a pair of non-negative integer arrays
(arr1, arr2)monotonic if:
- The lengths of both arrays are
n.arr1is monotonically non-decreasing, in other words,arr1[0] <= arr1[1] <= ... <= arr1[n - 1].arr2is 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
numsof lengthn.We call a pair of non-negative integer arrays
(arr1, arr2)monotonic if:
- The lengths of both arrays are
n.arr1is monotonically non-decreasing, in other words,arr1[0] <= arr1[1] <= ... <= arr1[n - 1].arr2is 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
nnodes labeled from0ton - 1, and rooted at node0. You are given a 2D integer arrayedgesof lengthn - 1, whereedges[i] = [ai, bi]indicates that there is an edge between nodesaiandbiin 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
treeNameis a tree consisting of a node intreeNameand all of its descendants.
There is a snake in an
n x nmatrixgridand can move in four possible directions. Each cell in thegridis 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
nrepresenting the size of thegridand an array of stringscommandswhere eachcommand[i]is either"UP","RIGHT","DOWN", and"LEFT". It’s guaranteed that the snake will remain within thegridboundaries throughout its movement.Return the position of the final cell where the snake ends up after executing
commands.