Strong and Weak Reference Lifecycle
Updated
Problem statement
You will simulate strong and weak handles that share control blocks. Each control block tracks one shared object, a strong count, and a weak count. Handle names are unique strings. Process operations in order:
["CREATE", strong]makes a new live object and one strong handle to it.["CLONE_STRONG", source, destination]adds another strong handle to the same block as the source.["MAKE_WEAK", source, destination]adds a weak handle to the same block as the source strong handle.["LOCK_WEAK", weak, destination]adds a strong destination handle, but only if the object is still live. If the object has expired, it adds no handle.["RELEASE", handle]removes one existing handle, strong or weak.["QUERY", handle]looks at the handle's block and changes nothing.
The object is LIVE while its strong count is above zero. It becomes EXPIRED at the moment that count drops to zero. The control block stays while any weak handle still points to it. It is REMOVED once both counts are zero.
After each operation, return one string for the block that operation touched. Use the counts after the operation and write strong:weak:LIVE or strong:weak:EXPIRED. When a release removes the control block, return 0:0:REMOVED. When a weak lock fails, return the block's expired state, which did not change.
Function
simulateReferenceControlBlocks(operations: String[][]) → String[]Examples
Example 1
operations = [["CREATE","s"],["MAKE_WEAK","s","w"],["CLONE_STRONG","s","s2"],["RELEASE","s"],["RELEASE","s2"],["LOCK_WEAK","w","late"],["QUERY","w"],["RELEASE","w"]]return = ["1:0:LIVE","1:1:LIVE","2:1:LIVE","1:1:LIVE","0:1:EXPIRED","0:1:EXPIRED","0:1:EXPIRED","0:0:REMOVED"]After s is created, given the weak handle w, and cloned into s2, the block has two strong handles and one weak handle. Releasing s drops the strong count to one. Releasing s2 drops it to zero, so the object expires. Locking w then fails. No handle named late is made, and the counts stay at zero strong and one weak. The query shows the same expired state. Releasing w brings both counts to zero, so the block is removed.
Example 2
operations = [["CREATE","owner"],["MAKE_WEAK","owner","observer"],["LOCK_WEAK","observer","locked"],["RELEASE","owner"],["QUERY","locked"],["RELEASE","locked"],["RELEASE","observer"]]return = ["1:0:LIVE","1:1:LIVE","2:1:LIVE","1:1:LIVE","1:1:LIVE","0:1:EXPIRED","0:0:REMOVED"]When observer is locked, the object is still live, so the lock makes a new strong handle locked. The strong count goes up to two. Releasing owner drops it to one. The object stays live because locked still holds it. Releasing locked drops the strong count to zero, so the object expires. Releasing observer then removes the block.
Example 3
operations = [["CREATE","a"],["CREATE","b"],["MAKE_WEAK","a","wa"],["RELEASE","a"],["QUERY","b"],["RELEASE","wa"],["RELEASE","b"]]return = ["1:0:LIVE","1:0:LIVE","1:1:LIVE","0:1:EXPIRED","1:0:LIVE","0:0:REMOVED","0:0:REMOVED"]a and b get separate blocks, each with its own counts. Releasing a expires only its object, and wa keeps that block around. Querying b still shows one strong handle, no weak handles, and a live object. Releasing wa removes the first block, and releasing b removes the second.
Constraints
1 <= operations.length <= 2000.- Every source or queried handle exists and has the required kind.
- Every destination handle name is fresh; a failed weak lock leaves it unused.
- Every release names an existing handle.
- Handle names contain from
1through30letters or digits.
More Squarepoint Capital Phone Screen questions
- Lazy Filter over a GeneratorPHONE SCREEN · Seen Nov 2026
- Moving Average of a Data StreamPHONE SCREEN · Seen Nov 2026
- 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
- Target Sum Across Two Sorted ArraysPHONE SCREEN · Seen Aug 2026
- Classify Heap Addresses from a Memory SnapshotPHONE SCREEN · Seen Nov 2025
Similar questions at other companies
- Design In-Memory File SystemSnowflake · PHONE SCREENSnowflake interview questions
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Dynamic Least-Loaded Job DispatcherCresta · PHONE SCREENCresta interview questions
- Sparse Vector and Matrix OperationsBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Capacity-Limited Timed CacheNetflix · PHONE SCREENNetflix interview questions
- Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
- LFU CacheFreshworks · PHONE SCREENFreshworks interview questions
- Tiered Expiring Item StoreAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Multi-Level Inventory Storage SystemOptiver · OA · PHONE SCREENOptiver interview questions
- Key-Value Store GET and PUT QPSDatabricks · PHONE SCREENDatabricks interview questions