Find Minimum Time
Problem Overview
- Compute the minimum time for a snake starting at 0 to eat at least k apples on a number line, moving at 1 unit/sec and eating instantly on contact.
- Inputs: n, k, and position array of n distinct integer coordinates; Output: an integer minimum time.
- Constraints: 1 ≤ n ≤ 1e5, 1 ≤ k ≤ n, |position[i]| ≤ 1e8, all positions unique.
- Context: Amazon gaming product simulating snake and apples on a number line.
- From Amazon interviews; a coding interview interview question problem.
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Input Variables
Execution Result:
