Battalions and Tanks Problem Statement

Given 'N' battalions and 'M' tanks, along with an array representing the number of soldiers in each battalion, you need to allocate the tanks such that the maximum ratio of soldiers per tank in any battalion is minimized.

The number of tanks is always assumed to be greater than the number of battalions.

Input:

The first line contains an integer 'T' indicating the number of test cases.
Each test case consists of two lines:
- The first line contains two integers 'N' and 'M', the number of battalions and the number of tanks, respectively.
- The second line contains 'N' space-separated integers representing the number of soldiers in each battalion.

Output:

For each test case, return the minimized maximum ratio of soldiers to tanks for any battalion.
The result should be accurate to within an absolute or relative error of at most 0.000001.

Example:

Suppose there is 1 test case with the following details:

Input:
T = 1
N = 3, M = 5
Soldiers[] = [10, 20, 30]

Possible Output:

Output:
6.000000

Constraints:

  • 1 ≤ T ≤ 50
  • 1 ≤ N ≤ 1000
  • N ≤ M ≤ 10000
  • 1 ≤ ARR[i] ≤ 1000000
  • Time limit: 1 sec
Note:
You only need to implement the function to return the answer, no need to handle input/output processes.
AnswerBot
4mo

Allocate tanks to battalions to minimize maximum ratio of soldiers per tank.

  • Calculate the ratio of soldiers to tanks for each battalion.

  • Sort the ratios in ascending order.

  • Return the maximum ratio from...read more

Help your peers!
Select
Add answer anonymously...

Amazon Software Developer Intern interview questions & answers

A Software Developer Intern was asked 4mo agoQ. Given a tree, find its diameter (the longest path between two nodes in the tree)...read more
A Software Developer Intern was asked 4mo agoQ. Given a matrix, find the shortest distance between two given points located anyw...read more
A Software Developer Intern was asked 4mo agoQ. For a given array, how would you count the number of inversions?

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked 4mo agoQ1. Given a tree, find its diameter (the longest path between two nodes in the tree)...read more
A Software Developer Intern was asked 4mo agoQ2. Given a matrix, find the shortest distance between two given points located anyw...read more
A Software Developer Intern was asked 4mo agoQ3. For a given array, how would you count the number of inversions?
Amazon Software Developer Intern 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