Object-Oriented Programming · Affirm · Medium
Implement a persistent stack named PStack. All operations must run in O(1) time. PStack(): Creates an empty stack. int size(): Returns the current number of elements. int peek(): Returns the most recently added element, without removing it. PStack push(int val): Produces a new PStack with val placed on top. PStack pop(): Produces a new PStack with the top element removed. Every push and pop call must return a brand-new stack instance and leave the original unchanged, so…
Checking your access…