Monthly Archive: January 2016


Dedupe an array in javascript

Input : An array Output : An array Logic : Iterate over the input array called data Add the element to the output array called result if the element does not exist in the...


Find duplicates in an array using javascript

Problem : Given an array of positive integers find all the duplicate elements. Algorithm : Iterate over the array using forEach Find if there is a duplicate for the element using indexOf indexOf takes...

Queue using two stacks javascript 0

Queue using two stacks javascript

Problem : Implement queue’s enqueue and dequeue operations using two stacks. Logic: The queue is first-in-first-out and a stack is last in-first-out phenomena. Hence, the main difference between these two data structures is that...


Sort the stack in ascending order

Problem : Sort the given stack into an ascending order without using recursion. Logic: Pop an item from the original stack and push it onto the sorted stack. If the poped item from the...

Tower of hanoi 0

Tower of hanoi

Problem : The Towers of Hanoi is a classic puzzle with 3 pegs and multiple disks of different sizes. The goal of the puzzle is to move all the disks from the first peg...

Show Buttons
Hide Buttons