Sum of On Switch Indices
Updated
Problem 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 Online Assessment questions
- 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
- Binary Search Tree IteratorOA · Seen Nov 2023
- Binary Tree Level Order TraversalOA · Seen Nov 2023
Similar questions at other companies
- Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
- Sliding-Window Means with IEEE Special ValuesHeadlands Technologies · OAHeadlands Technologies interview questions
- Last Object to Fall Off the TableConfluent · OAConfluent interview questions
- Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Earliest Meeting Time for All EmployeesCapital One · OACapital One interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
- Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
- Largest Team Where Every Pair OverlapsWalmart · OAWalmart interview questions