Find the number of distinct Islands OR connected components.

Objective: Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of distinct or unique islands. … Read more

Check if Graph is Bipartite – Adjacency List using Depth-First Search(DFS)

Objective: Given a graph represented by the adjacency List, write a Depth-First Search(DFS) algorithm to check whether the graph is … Read more

Evaluation of Prefix Expressions (Polish Notation) | Set 2

Earlier we had discussed how to evaluate prefix expression where operands are of single-digit. In this article, we will discuss … Read more

Evaluation of Prefix Expressions (Polish Notation) | Set 1

Prefix notation is a notation for writing arithmetic expressions in which the operands appear after their operators. There are no … Read more

Convert Prefix to Postfix Expression

Objective: Given a Prefix expression, write an algorithm to convert it into Postfix expression. Example: Input: Prefix expression:  + A … Read more

Convert Postfix to Prefix Expression

Objective: Given a Postfix expression, write an algorithm to convert it into prefix expression. Example: Input: Postfix expression:  A B … Read more

Convert Postfix to Infix Expression

Objective: Given a Postfix expression, write an algorithm to convert it into Infix expression. Example: Input: Postfix expression:  A B … Read more

Convert Prefix to Infix Expression

Objective: Given a Prefix expression, write an algorithm to convert it into Infix expression. Example: Input: Prefix expression: + A … Read more

Convert Infix to Prefix Expression

Objective: Given an Infix expression, write an algorithm to convert it into Prefix expression. Example: Input: Infix expression – A … Read more

Convert Infix to Postfix Expression

Objective: Given an Infix expression, write an algorithm to convert it into Postfix expression. Example: Input: Infix expression – A … Read more

Evaluation of Infix expressions

Infix notation is commonly used in arithmetic formula or statements, the operators are written in-between their operands. Let’s assume the … Read more

Dynamic Programming – Count all paths in 2D Matrix with Obstructions in it

Objective: Given a two-dimensional matrix, write an algorithm to count all possible paths from the top left corner to the bottom-right corner. You are allowed to move only in two directions, move right OR move down. There are few obstructions as well, which means few cells are blocked and you cannot travel that cell.

Many times this problem is referred to as the “Robot Travel Problem”. Given a 2d matrix, how many ways a robot can travel from the top left corner to the bottom right corner and there are few cells in which the robot cannot travel?

Read more

Kadane’s Algorithm – Maximum Subarray Problem

Objective:  The maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional array of numbers that has the largest … Read more

Reverse a Linked List in groups of given size ‘K’

Objective: Given a linked list and integer ‘k’, write an algorithm to reverse the linked list in groups of size … Read more