Cipher Cover Interval Editing
Updated
Problem statement
A book is a source string. The ordered list cover describes a cipher: for every inclusive interval [start, end], append book[start..end] to the cipher in list order.
Delete the cipher character at the zero-based flattened index position by updating the cover rather than changing book. Return the updated list of intervals.
Cover update rules
- If the selected character is the first endpoint of a multi-character interval, increase that interval's start by
1. - If it is the last endpoint of a multi-character interval, decrease that interval's end by
1. - If it is strictly inside an interval, replace that interval with its nonempty left and right pieces, in that order.
- If the selected interval contains exactly one character, remove that interval.
The order of cover defines the cipher. Intervals may be unsorted and may overlap. Deleting one cipher occurrence changes only the interval that produced that occurrence; another interval may continue to reference the same position in book. Preserve all unaffected interval boundaries and do not merge adjacent intervals.
Function
deleteCipherCharacter(book: String, cover: int[][], position: int) → int[][]Examples
Example 1
book = "abcdefghij"cover = [[1,4],[7,9]]position = 2return = [[1,2],[4,4],[7,9]]The first interval contributes bcde, so flattened position 2 is d at book index 3. Removing that interior character splits [1,4] into [1,2] and [4,4].
Example 2
book = "abcdef"cover = [[4,5],[0,2]]position = 0return = [[5,5],[0,2]]The cipher begins with book[4]. Deleting the first character shrinks the first interval from the left. The unsorted interval order is preserved.
Example 3
book = "abcdef"cover = [[1,3],[2,2],[0,1]]position = 3return = [[1,3],[0,1]]Flattened position 3 comes from the singleton interval [2,2], so that interval is removed. The earlier overlapping interval still references book index 2.
Constraints
1 <= book.length <= 10^5.1 <= cover.length <= 10^5.- Every interval has exactly two integers
[start, end]with0 <= start <= end < book.length. - The sum of all inclusive interval lengths is at most
2 * 10^5. 0 <= position < sum(end - start + 1)over all intervals.- Intervals may be unsorted and may overlap.
More Databricks Onsite Interview questions
- Rolling Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Path Between Two Nodes of a Fibonacci TreeONSITE INTERVIEW · Seen Oct 2026
- Rectangular K-in-a-RowONSITE INTERVIEW · Seen Oct 2026
- Customer Revenue with Direct ReferralsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- File Encryption Tree OptimizationPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Hybrid Run-Length and Bit-Packing EncoderONSITE INTERVIEW · Seen Aug 2026
- Concurrent Buffered File LoggerONSITE INTERVIEW · Seen Aug 2026
- Key-Value Store with Hit CounterONSITE INTERVIEW · Seen Jul 2026
- Blocking Keyed Cache with Waiting ReadersONSITE INTERVIEW · Seen Jul 2026
- Snapshot Set IteratorPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Digit-Coded Card ValidationCapital One · ONSITE INTERVIEWCapital One interview questions
- Online Meeting Scheduler with Fixed RoomsUber · ONSITE INTERVIEWUber interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Path Leaf Character IteratorGoogle · ONSITE INTERVIEWGoogle interview questions
- Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- First-Fit Arena AllocatorAMD · PHONE SCREEN · ONSITE INTERVIEWAMD interview questions
- Hex Dump FormatterWaymo · ONSITE INTERVIEWWaymo interview questions
- Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions
- Parse Command-Line TokensSamsara · ONSITE INTERVIEWSamsara interview questions