Skip to main content

Practice · 3 of 5

Aggressive Cows (Beginner)

CHALLENGE
Difficulty: intermediate+25 XP

**Description:** Given n stall positions on a line and k cows, place all cows in distinct stalls so the minimum distance between any two cows is as large as possible. Print that distance. **Input:** Line 1: n k (2 <= k <= n <= 10^5). Line 2: n distinct positions (0 <= p_i <= 10^9). **Output:** One integer — the largest achievable minimum distance. **Example:** 5 3 / 1 2 8 4 9 -> 3 (place at 1, 4, 8 or 1, 4, 9).

Back to lesson: Practice: Search Set