Clone a stack without usinig extra space
Medium Accuracy: 88.39% Submissions: 1925 Points: 4

Given elements of a stack, clone the stack without using extra space.

Example 1:

N = 10
st[] = {1, 1, 2, 2, 3, 4, 5, 5, 6, 7}

Your Task:  
You don't need to read input or print anything. Your task is to complete the function clonestack() which takes the input stack st[], an empty stack cloned[], you have to clone the stack st into stack cloned.
The driver code itself prints 1 in the output if the stack st is cloned properly and prints 0 otherwise.

Expected Time Complexity: O(N*N)
Expected Auxiliary Space: O(1)


1 <= N <= 1000

1<= st[i] <= 105

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Clone a stack without usinig extra space

Output Window