This problem can be solved using stack.
Step1: Insert all the elements in the list1 into a stack say s1
Step2: Insert all the elements in the list2 into a stack say s2
while(!s1.empty() || !s2.empty())
Note: insertintoll() function inserts the value to the front of the new linked list
We can put each element in a tree say BST and then print the tree in inorder or store the elements into an another array inorder.
1. Hey guys use two for loop and compute the count for each item and check whether count%2==0 if the condition gets satisfied then print the result
Time Complexity: O(N2) Space Complexity: O(1)
2. Sort the list and use two pointers to check the count and check the same condition as i have mentioned above and if that gets satissfied print the result
Time Complexity: O(N) Space Complexity : O(1)
1. We can use one stack. initialise i=0 and flag=0 stack and queue- vigneshb06 August 10, 2013
insert 2^i elements and elements from stack into the queue and set flag=~flag
insert 2^i elements into the stack and remove element one by one and insert into the tree..set flag=~flag
3. do the above step until DLL is empty