We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Collections
- Piling Up!
- Discussions
Piling Up!
Piling Up!
Sort by
recency
|
984 Discussions
|
Please Login in order to post a comment
T = int(input()) for j in range(T): n = int(input()) blocks = list(map(int, input().split())) result = True left, right = 0, n-1 top = float('inf') while left <= right: if blocks[left] <= top and (blocks[left] >= blocks[right]): top = blocks[left] left += 1 elif blocks[right] <= top: top = blocks[right] right -= 1 else: result = False break
Here, it's my code!
The description of this is terrible. This is what it's trying to ask of you.
You’re given a row of cubes, each with a length. You can only pick cubes from either end — leftmost or rightmost — one at a time. Your goal is to stack them vertically, so that each cube you place is not longer than the one below it. In other words: - You’re building a pile from bottom to top. - Each new cube must be equal to or smaller than the one you just placed. - You can only pick from the ends of the row — no grabbing from the middle.