Problem · Array
Sum of On Switch Indices
Learn this problemProblem statement
Switches are numbered with positive consecutive indices and initially are off. Each operation [left, right] toggles every switch in that inclusive interval.
After every operation has been applied, return the sum of the indices of all switches that are on.
Function
sumOnSwitchIndices(operations: int[][]) → longExamples
Example 1
operations = [[1,4],[2,6],[1,6]]return = 9Only switches 2, 3, and 4 finish on, so the sum is 9.
Constraints
1 <= operations.length <= 2000001 <= left <= right <= 10^9- The answer fits a signed
long.
More Atlassian problems
- Planning ProductionOA · Seen Feb 2025
- K-Means ClusteringOA · Seen Feb 2025
- Minimum Sorted Erasure OperationsOA · Seen Jun 2024
- Count Analogous ArraysOA · Seen Mar 2024
- Get Maximum ScoreOA · Seen Mar 2024
- Better Compression 🦀OA · Seen Mar 2024
- Romanizer 🐡OA · Seen Mar 2024
- Flower Bouquets 💐OA · Seen Mar 2024