Given an array of size n, let’s assume an element is ‘touched’ if and only if some operation is performed on it(for example, for performing

Nguyễn Hào

New member
Given an array of size n, let’s assume an element is ‘touched’ if and only if some operation is performed on it(for example, for performing a pop operation the top element is ‘touched’). Now you need to perform Dequeue operation. Each element in the array is touched atleast?
A. Once
B. Twice
C. Thrice
D. Four times
 
Answer: D
Explanation: First each element from the first stack is popped, then pushed into the second stack, dequeue operation is done on the top of the stack and later the each element of second stack is popped then pushed into the first stack. Therfore each element is touched four times.
 

Tìm kiếm

Back
Top