Number of Islands

In this tutorial, I am going to discuss a very famous interview problem. How to count the number of islands.

Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically.

You may assume all four edges of the grid are surrounded by water.

Implement Queue using Two Stacks – Java Code & Algorithm

How to implement a queue using two stacks. In this tutorial, I am going to discuss how to implement a first in first out (FIFO) queue using only two stacks.

In this problem, we are going to implement following methods of QueueUsingStack class:

void push(int x) – Insert an element x.
int pop() –  Removes the element (In FIFO order).
int peek() – Returns the element which is present at the front of the queue.
boolean empty() – Returns true if no element is present else false.

For example –

MCQ on Stack and Queue – Data Structure Practice Questions

MCQ on stack and queue data structure. Both Stack and Queue data structure is very important in computer science. In this tutorial, you are going to learn about stack and queue data structure. Also you’ll find MCQ on stack and queues.

In my previous post, i have discussed how to implement stack and queue data structure.

Stack program in C using Array.

Queue data structure and their implementation.

The purpose of this objective questions is to test how well you understand the concept of stack and queue.