
Asked in PeopleStrong
Aggressive Cows Problem Statement
Given an array representing positions of stalls and an integer ‘K’ representing the number of aggressive cows, determine the largest minimum distance between any two cows when they are placed in the stalls such that they are as far apart as possible to prevent aggression.
Input:
The first line contains an integer ‘T’ representing the number of test cases.
For each test case:
The first line contains two integers, ‘N’ and ‘K’, where ‘N’ is the number of stalls, and ‘K’ is the number of cows.
The second line contains ‘N’ space-separated integers, each representing the position of a stall.
Output:
For each test case, output the largest minimum distance between any two cows placed in stalls.
Example:
Input:
T = 1
N = 5, K = 3
ARR = [1, 2, 8, 4, 9]
Output:
3
Constraints:
1 <= T <= 5
2 <= N <= 20000
2 <= K <= N
0 <= ARR[i] <= 10^9
- Time Limit: 1 sec.
Note:
No need to print anything. The function should return the result for each test case.

AnswerBot
1y
The problem requires assigning aggressive cows to stalls in a way that maximizes the minimum distance between any two cows.
Sort the array of stall positions in ascending order.
Use binary search to fin...read more
Help your peers!
Add answer anonymously...
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for PeopleStrong Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

