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.
Deepak Kumar
1y
#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!
Add answer anonymously...
Top DE Shaw Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in DE Shaw Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app