FastPrepTrace Nested Object Destruction Order
Problems/Trace Nested Object Destruction Order

Trace Nested Object Destruction Order

Arista Networks logoArista Networks● MediumFULLTIMENEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Arista Networks phone screen for full-time and new grad roles. The report is an output task about how long objects live and the order they are destroyed. We chose these: nested scopes, objects with names, and cleanup at the end of the program. Our version is about 82% the same as the reported question.

Simulate automatic object lifetimes in nested scopes. Operations are enter, create:name, or exit. A created object belongs to the current scope. Exiting destroys that scope's objects in reverse creation order.

After all operations, destroy remaining scopes from innermost to outermost. Return object names in destruction order.

Function

destructionOrder(operations: String[]) → String[]

Examples

Example 1

operations = ["create:a","enter","create:b","create:c","exit"]return = ["c","b","a"]

The inner scope closes first, then the outer scope closes at the end.

Example 2

operations = ["enter","exit"]return = []

Empty scopes destroy nothing.

Constraints

  • 0 <= operations.length <= 100000.
  • Names are nonempty ASCII strings without a colon.
  • Every explicit exit has a matching active scope.

Source note: Author-written prompt excerpt retained for source fidelity.

More Arista Networks interview questions

  • First Missing Number in a Consecutive ArrayOA · PHONE SCREEN · Seen Oct 2026
  • Remove All Repeated Values from a Linked ListPHONE SCREEN · Seen Oct 2026
  • Trace Pointer Rebinding and Pointee UpdatesPHONE SCREEN · Seen Oct 2026
  • Swap Adjacent NibblesPHONE SCREEN · Seen Aug 2026
  • Unique Target-Sum Pairs in a Sorted Doubly Linked ListPHONE SCREEN · Seen Aug 2026
  • Generic Stack Operation SequencePHONE SCREEN · Seen Aug 2026
  • API Bandwidth AllocationOA · Seen Sep 2026
  • LFU CacheOA · Seen Sep 2026
  • Maximum Server Processing TimeOA · Seen Aug 2026
  • Minimum Adjacent Merges to Form a PalindromeOA · Seen Aug 2026

Similar questions at other companies

  • Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
  • Run a Stack Language InterpreterJane Street · PHONE SCREENJane Street interview questions
  • Stack Language EvaluatorRetell AI · PHONE SCREENRetell AI interview questions
  • Text Document HistoryNotion · PHONE SCREEN · ONSITE INTERVIEWNotion interview questions
  • Text Editor, Part 2: Undo and RedoOpenAI · PHONE SCREENOpenAI interview questions
  • One-Dimensional Candy CrushBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions
All Arista Networks interview questionsSee Arista Networks hiring insights
Saved
class Solution {
    public String[] destructionOrder(String[] operations) {
        // Write your code here.
    }
}
Checking account…