Header Ads Widget

Bag Of Numbers

 Problem:-

Vikas is given a bag which consists of numbers (integers) blocks,Vikas has to organize the numbers again in the same order as he has inserted it into the bag, i.e. the first number inserted into the bag by Vikas should be picked up first followed by other numbers in series. Help Vikas to complete this work in O(n) time complexity with the condition to use one extra bag to complete the work (assume that the bags are compact and is in the form of a stack structure and has the same width as that of the number blocks and is large enough to fill the bag to the top and the number taken from bag is in reverse order).

Hint: You may use the concept of Stacks.

Sample Input
input: 15 21 39 390 392 380.
Sample Output
output: 15 21 39 390 392 380.
Time Limit: 1
Memory Limit: 256
Source Limit:

Code:-

string=input()
mylist=string.split()
if(len(mylist)>3):
print("output:",end=" ")
else:
print("output",end=" ")
for i in range(1,len(mylist)):
print(mylist[i],end=" ")



Post a Comment

0 Comments