Last active
April 6, 2026 17:45
-
-
Save aquaflamingo/0ef6cb930c130342cc51daf835b8407c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Problem Statement: | |
| # | |
| # You are designing a basic garbage collection algorithm class. | |
| # | |
| # The goal of the class is to output an modified version of the input array containing | |
| # references to live objects, the remainder of objects will later be cleared by a function that | |
| # trims all the values | |
| # | |
| # Implement a function that returns a modified array containing a continous sub array of | |
| # live objects and their indices so that all dead objects can be chopped off by the garbage collector. | |
| # | |
| # You may not use any additional array space. | |
| # | |
| # Input | |
| # arr [o1(live), o2(dead), o3(live), o4(dead), o5(dead)] | |
| # | |
| # Output | |
| # arr [{o1,o3},o3,o4,o5]; {} denotes the live objects | |
| # sub arr index: [0,1] | |
| # | |
| # Extension: | |
| # We can no longer assume the first object will be alive | |
| # Adjust the algorithm to handle this | |
| # | |
| # Input | |
| # arr [o1(dead), o2(live), o3(dead), o4(live), o5(dead)] | |
| # | |
| # Output | |
| # arr [o1,{o2,o4},o4,o5]; | |
| # sub arr index: [1,2] | |
| # | |
| # Class: Two Pointers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment