Tap here to switch tabs
Problem
Submissions

Problem: Minimum Time to Eat All Grains

Minimum Time to Eat All Grains gives hens and grains positions on a line. Find the least time for hens moving one unit per second to reach and eat every grain, with simultaneous movement allowed.

Statement

You are given two 00 indexed integer arrays hens and grains, representing the initial positions of hens and grains along a line.

In each second, any hen can move 11 unit to the left or 11 unit to the right, or remain at its current location. When a hen reaches the position of a grain, it eats the grain instantly. All hens can move simultaneously.

Return the minimum time in seconds needed for the hens to eat all the grains.

Constraints:

  • 1≤1 \leq hens.length, grains.length ≤2⋅104\leq 2 \cdot 10^4

  • 0≤0 \leq hens[i], grains[j] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Time to Eat All Grains

Minimum Time to Eat All Grains gives hens and grains positions on a line. Find the least time for hens moving one unit per second to reach and eat every grain, with simultaneous movement allowed.

Statement

You are given two 00 indexed integer arrays hens and grains, representing the initial positions of hens and grains along a line.

In each second, any hen can move 11 unit to the left or 11 unit to the right, or remain at its current location. When a hen reaches the position of a grain, it eats the grain instantly. All hens can move simultaneously.

Return the minimum time in seconds needed for the hens to eat all the grains.

Constraints:

  • 1≤1 \leq hens.length, grains.length ≤2⋅104\leq 2 \cdot 10^4

  • 0≤0 \leq hens[i], grains[j] ≤109\leq 10^9