String Copy and Move Lifecycle
Updated
Problem statement
Implement the value behavior of a String class with copy and move construction and assignment. Process commands in order, starting with no named objects.
For this exercise, assume these commands:
["NEW", name, text]constructs a new object.["COPY", source, destination]copy-constructs a new destination with independent character storage.["MOVE", source, destination]move-constructs a new destination and makes the source empty.["COPY_ASSIGN", destination, source]replaces an existing destination with an independent copy.["MOVE_ASSIGN", destination, source]replaces an existing destination by moving the source value, then makes the source empty.["APPEND", name, suffix]appends characters to one object.["GET", name]records its current text.
Return the recorded texts in order. Both forms of self-assignment leave the object unchanged. A moved-from object remains usable as an empty string. Appending to one copy must not change another.
Function
simulateStringValues(commands: String[][]) → String[]Examples
Example 1
commands = [["NEW","a","ab"],["COPY","a","b"],["APPEND","a","c"],["GET","a"],["GET","b"]]return = ["abc","ab"]The copy starts with ab. Appending to a changes it to abc while b stays ab.
Example 2
commands = [["NEW","a","cat"],["MOVE","a","b"],["GET","a"],["GET","b"],["APPEND","a","x"],["GET","a"],["GET","b"]]return = ["","cat","x","cat"]Moving transfers cat into b and empties a. Reusing the empty source with an append produces x without changing b.
Example 3
commands = [["NEW","a","a"],["NEW","b","b"],["COPY_ASSIGN","a","b"],["MOVE_ASSIGN","b","a"],["GET","a"],["GET","b"]]return = ["","b"]Copy assignment first gives a the value b. Moving that value back into the existing b object empties a.
Constraints
0 <= commands.length <= 200.- Each command has
2or3tokens. - Every token has length at most
50. - Commands follow the listed shapes and reference valid existing objects. Constructor destinations are new names. Names match
[a-z][a-z0-9]{0,11}; text and suffixes contain only lowercase English letters and may be empty. - No object text exceeds
5000characters, and all returned text contains at most30000characters in total.
More Squarepoint Capital Phone Screen questions
- Newton Square Root to a Guaranteed TolerancePHONE SCREEN · Seen Nov 2026
- Probability of Consecutive HeadsPHONE SCREEN · Seen Nov 2026
- Three Points in a Semicircle: Monte Carlo EstimatePHONE SCREEN · Seen Nov 2026
- Combine Two Index SequencesPHONE SCREEN · Seen Aug 2026
- Parse, Normalize, and Combine PolynomialsPHONE SCREEN · Seen Aug 2026
- Sorted Insertion SnapshotsPHONE SCREEN · Seen Aug 2026
- Strong and Weak Reference LifecyclePHONE SCREEN · Seen Aug 2026
- Target Sum Across Two Sorted ArraysPHONE SCREEN · Seen Aug 2026
- Classify Heap Addresses from a Memory SnapshotPHONE SCREEN · Seen Nov 2025
- Fixed Worker Pool with a Shared QueuePHONE SCREEN · Seen Nov 2025
Similar questions at other companies
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
- Numeric Poker OperationsRippling · PHONE SCREENRippling interview questions
- Reference-Counted Deduplicating File SystemCitadel · PHONE SCREENCitadel interview questions
- Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
- Design In-Memory File SystemSnowflake · PHONE SCREENSnowflake interview questions
- In-Memory Vault File SystemHarvey · ONSITE INTERVIEWHarvey interview questions
- Parcel Event TrackingAirbnb · OAAirbnb interview questions
- Account Scheduler - Availability and AcquireStripe · ONSITE INTERVIEWStripe interview questions