This repository was archived by the owner on Oct 5, 2025. It is now read-only.

Description
def aggressiveCows(stalls: list[int], k: int) -> int:
stalls.sort()
low = 1
high = stalls[-1] - stalls[0]
result = 0
def can_place_cows(distance: int) -> bool:
count = 1
last_pos = stalls[0]
for i in range(1, len(stalls)):
if stalls[i] - last_pos >= distance:
count += 1
last_pos = stalls[i]
if count == k:
return True
return False
while low <= high:
mid = (low + high) // 2
if can_place_cows(mid):
result = mid
low = mid + 1
else:
high = mid - 1
return result