Execute Cursor-Based Text Editor Operations
Updated
Problem statement
Start with an empty document and cursor position 0. Each command is [operation,argument].
INSERT textinserts at the cursor and moves past it.LEFT xandRIGHT xmove without crossing an edge.BACKSPACE xremoves up to x characters immediately left of the cursor and moves to the deletion start.DELETE xremoves up to x characters immediately right of the cursor without moving it.PRINT xrecords characters at indices fromcursor-xthroughcursor+x, inclusive and clipped to the document.
Return recorded strings in print order.
Function
getPrintedStrings(commands: String[][]) → String[]Examples
Example 1
commands = [["Insert","addthis"],["Print","5"],["Left","4"],["Right","2"],["Backspace","1"],["Delete","1"],["Print","10"]]return = ["dthis","addts"]The print results are dthis and addts.
Example 2
commands = [["Insert","abc"],["Left","2"],["Insert","XY"],["Print","3"]]return = ["aXYbc"]Insertion at cursor one creates aXYbc and the cursor sits after XY.
Example 3
commands = [["Print","2"]]return = [""]Printing an empty document records an empty string.
Constraints
1 <= commands.length <= 5000.- The total inserted length is at most 5000.
- Numeric arguments are nonnegative decimal integers.
More DocuSign Phone Screen questions
- Symmetric Binary TreePHONE SCREEN · Seen Oct 2026
- Union Area of Two RectanglesPHONE SCREEN · Seen Oct 2026
- Minimize Array Sum After K Halving OperationsPHONE SCREEN · Seen Sep 2026
- Fizz and Buzz Words From 1 to nPHONE SCREEN · Seen Sep 2026
- Two Positions That Add Up to a TargetPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Rain Kept Between WallsPHONE SCREEN · Seen Mar 2026
- Exact Palindrome CheckPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
- Reverse the Characters of a TextPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
- Rebuild a Trip From Flight TicketsPHONE SCREEN · Seen Apr 2019
- Find the Words for Each PrefixPHONE SCREEN · Seen Sep 2018
Similar questions at other companies
- Business Account KYC Verification — Parts 1–5Stripe · PHONE SCREENStripe interview questions
- Minimum Number of Frogs CroakingCerebras · PHONE SCREEN
- Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Read Across Sound TracksAirbnb · PHONE SCREENAirbnb interview questions
- Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- K-Step Bit Flip with RetentionCisco · PHONE SCREENCisco interview questions
- Elevator Scheduling SimulationOpenAI · PHONE SCREENOpenAI interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions