Educational Codeforces Round 144 (Rated for Div. 2) D. Maximum Subarray
2867. Count Valid Paths in a Tree
There is an undirected tree with
nnodes labeled from1ton. You are given the integernand a 2D integer arrayedgesof lengthn - 1, whereedges[i] = [ui, vi]indicates that there is an edge between nodesuiandviin the tree.Return the number of valid paths in the tree.
A path
(a, b)is valid if there exists exactly one prime number among the node labels in the path fromatob.Note that:
- The path
(a, b)is a sequence of distinct nodes starting with nodeaand ending with nodebsuch that every two adjacent nodes in the sequence share an edge in the tree.- Path
(a, b)and path(b, a)are considered the same and counted only once.
You are given a 0-indexed array
maxHeightsofnintegers.You are tasked with building
ntowers in the coordinate line. Theithtower is built at coordinateiand has a height ofheights[i].A configuration of towers is beautiful if the following conditions hold:
1 <= heights[i] <= maxHeights[i]heightsis a mountain array.Array
heightsis a mountain if there exists an indexisuch that:
- For all
0 < j <= i,heights[j - 1] <= heights[j]- For all
i <= k < n - 1,heights[k + 1] <= heights[k]Return the maximum possible sum of heights of a beautiful configuration of towers.
You are given a 0-indexed array
maxHeightsofnintegers.You are tasked with building
ntowers in the coordinate line. Theithtower is built at coordinateiand has a height ofheights[i].A configuration of towers is beautiful if the following conditions hold:
1 <= heights[i] <= maxHeights[i]heightsis a mountain array.Array
heightsis a mountain if there exists an indexisuch that:
- For all
0 < j <= i,heights[j - 1] <= heights[j]- For all
i <= k < n - 1,heights[k + 1] <= heights[k]Return the maximum possible sum of heights of a beautiful configuration of towers.
2864. Maximum Odd Binary Number
You are given a binary string
sthat contains at least one'1'.You have to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number that can be created from this combination.
Return a string representing the maximum odd binary number that can be created from the given combination.
Note that the resulting string can have leading zeros.