Tower Building Problem Statement

Given an array 'ARR' of 'N' cubes, you need to construct towers such that each cube can either be placed on top of an existing tower or start a new one. The restriction is that the top cube on a tower must be smaller than the one below it. Your task is to determine the minimum number of towers needed when processing the cubes in the given order.

Example:

Input:
N = 3, ARR = [3, 2, 1]
Output:
1
Explanation:

All cubes can be stacked into one tower where the arrangement is 3 at the bottom, 2 in the middle, and 1 on top.

Input:

The first line contains an integer 'T', the number of test cases. Each test case starts with an integer 'N', indicating the number of cubes, followed by 'N' space-separated integers representing the elements of the array 'ARR'.

Output:

For each test case, print a single integer on a new line indicating the minimum possible number of towers.

Constraints:

  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 2000
  • 1 ≤ ARR[i] ≤ 2000

Time limit: 1 second.

Note:

No need to handle input/output. Focus on implementing the function to return the result.

AnswerBot
4mo

The task is to determine the minimum number of towers needed to stack cubes in a specific order.

  • Iterate through the array of cubes and maintain a stack to keep track of towers.

  • For each cube, check if ...read more

Deepak Kumar
2y
#arr = [4,5,1,2], n = len(arr) ans = 0 for i in range(0,n): if arr[i] < arr[i+1] : i +=1 if arr[i] > arr[i+1] or i == n-1 : ans +=1 i +=1 return ans
Help your peers!
Select
Add answer anonymously...

DE Shaw Software Developer interview questions & answers

A Software Developer was asked 12mo agoQ. Given a binary tree and a target node, burn the tree starting from the target no...read more
A Software Developer was asked Q. What is the purpose of Normalization?
A Software Developer was asked Q. What is the difference between a default constructor and a copy constructor?

Popular interview questions of Software Developer

A Software Developer was asked 12mo agoQ1. Given a binary tree and a target node, burn the tree starting from the target no...read more
A Software Developer was asked Q2. What is the purpose of Normalization?
A Software Developer was asked Q3. What is the difference between a default constructor and a copy constructor?
DE Shaw Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits