Minimum Start Value

Problem Overview

  • Determine the minimum positive start value x so the running sum with the array stays at least 1 after every step.
  • Input: int array arr[n]. Output: long minimum start value. Constraints: 1≤n≤1e5, −1e6≤arr[i]≤1e6.
  • Context: Model maintaining a positive running balance or safety margin across sequential gains/losses.
  • Source: Asked in Goldman interviews; a coding interview problem and common interview question.

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: