Aggressive cows

Farmer John has built a new long barn, with N stalls.
Given an array of integers A of size N where each element of the array represents the location of the stall,
and an integer B which represent the number of cows.

His cows don’t like this barn layout and become aggressive towards each other once put
into a stall. To prevent the cows from hurting each other, John wants to assign the cows to the stalls,
such that the minimum distance between any two of them is as large as possible. What is the largest minimum distance?



Input Format

The first argument given is the integer array A.
The second argument given is the integer B.

Output Format

Return the largest minimum distance possible among the cows.

Constraints

2 <= N <= 100000
0 <= A[i] <= 10^9
2 <= B <= N

For Example

Input 1:
    A = [1, 2, 3, 4, 5]
    B = 3
Output 1:
    2

Input 2:
    A = [5, 17, 100, 11]
    B = 2
Output 2:
    95
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Aggressive cows on Interview Code Editor
Sign Up
to access hints and editorial solutions for Aggressive cows

Discussion


Loading...
Click here to start solving coding interview questions