Calculate the Sum
Problem Overview
- Apply inclusive range toggles to a row of switches (all start off) and compute the sum of indices that end up on.
- Input: n operations and a 2D array of [left, right] indices (1-based); Output: integer sum of on switch indices.
- Context: models NOT operations on consecutive two-position switches in a simple electrical row.
- From Expedia interviews; this problem is a common coding interview 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:
