Range Module
Updated
Problem statement
Process a finite ordered sequence of operations for a range module. The module starts with no tracked points on the number line. The arrays operations and ranges have the same length. At step i, ranges[i] = [left, right] supplies the integer endpoints of the valid half-open interval [left, right), where left < right.
Operation Contract
addRange: track every point in[left, right).removeRange: stop tracking every point in[left, right).queryRange: producetrueexactly when every point in[left, right)is currently tracked; otherwise producefalse.
Apply the operations in encounter order and return a boolean[] containing the results of the queryRange operations in that same order. The update operations do not contribute values to the returned array.
Function
rangeModule(operations: String[], ranges: int[][]) → boolean[]Examples
Example 1
operations = ["addRange","removeRange","queryRange","queryRange","queryRange"]ranges = [[10,20],[14,16],[10,14],[13,15],[16,17]]return = [true,false,true]After adding [10,20) and removing [14,16), the module tracks [10,14) and [16,20). Therefore [10,14) is fully tracked, [13,15) crosses the removed gap, and [16,17) is fully tracked.
Example 2
operations = ["addRange","addRange","queryRange","removeRange","queryRange","queryRange","queryRange"]ranges = [[1,5],[5,8],[1,8],[3,6],[1,3],[3,6],[6,8]]return = [true,true,false,true]The adjacent additions combine to cover [1,8). Removing [3,6) leaves [1,3) and [6,8), so only the query for the removed middle interval is false.
Example 3
operations = ["queryRange","addRange","removeRange","queryRange","addRange","queryRange","queryRange"]ranges = [[1,2],[2,4],[1,5],[2,4],[3,7],[4,6],[2,3]]return = [false,false,true,false]The first query is false because the module is empty. The first added range is completely removed. Adding [3,7) then covers [4,6), but it does not cover [2,3).
More Walmart Phone Screen questions
- Count Months Starting on SundayPHONE SCREEN · Seen Aug 2026
- Longest Even-Length WordPHONE SCREEN · Seen Aug 2026
- Meeting Rooms IIPHONE SCREEN · Seen Aug 2026
- Sort Real Number StringsPHONE SCREEN · Seen Jan 2026
- Check a Password Against a Supplied PolicyPHONE SCREEN · Seen Jun 2025
- Convert a Restricted Function to an Arrow FunctionPHONE SCREEN · Seen Jun 2025
- Repair One Missing Function Punctuation CharacterPHONE SCREEN · Seen Jun 2025
- Can the Singer Perform the Song?PHONE SCREEN · Seen Mar 2025
- Rooms With Two Other Entrances and a Treasure SuccessorPHONE SCREEN · Seen Mar 2025
- First Dictionary Word from Note LettersPHONE SCREEN · Seen Aug 2022
Similar questions at other companies
- Delivery Cost Tracker with Effective-Dated RatesRippling · PHONE SCREENRippling interview questions
- Employee Ratings Management SystemAmazon · PHONE SCREEN
- Running Medians and PercentilesStackAdapt · PHONE SCREENStackAdapt interview questions
- Order Sequence Prefix Counts and QuantitiesHeadlands Technologies · PHONE SCREENHeadlands Technologies interview questions
- Memory AllocatorOpenAI · PHONE SCREENOpenAI interview questions
- Query Weekly Store Opening HoursApple · PHONE SCREENApple interview questions
- In-Memory Meeting Room ManagerRunloop · PHONE SCREEN
- Interview Slot BookingTrueFoundry · PHONE SCREEN
- Worker Management with Promotions and Double-Paid TimeInstacart · ONSITE INTERVIEWInstacart interview questions
- Worker Management (Promotion Track), Part 4: Full-Shift Double PayAirbnb · OAAirbnb interview questions