Nov 222016

Given a Matrix of order M*N, where each cell can have zero or one orange. The orange in the cell (if present) can be either fresh or rotten. A rotten orange will rot the fresh oranges in the nearby cell in unit time. If a rotten orange is in cell (i,j), then it will rot the fresh oranges present in cells

(i+1, j) (i-1, j) (i, j+1) (i, j-1)

in unit time (say one minute). If a fresh orange is surrounded by all empty cells then it cannot be rotten at all. Given the below matrix Continue reading »

Sep 172013

We have seen how to implement Queue using a linked list and using Array as the base data structure.  The question here is that given two Stacks, say S1 and S2, and no other data structure, simulate the functionality of a Queue, hence use two stacks as the base data structure for a Queue.

i.e we should expose two functions enqueue and dequeue which will insert the element and return it in FIFO order (First In First Out). Continue reading »