Distance of nearest cell having 1 in a binary matrix

Problem Statement The problem “Distance of nearest cell having 1 in a binary matrix” states that you are given a binary matrix(containing only 0s and 1s) with at least one 1. Find the distance of the nearest cell having 1 in the binary matrix for all the elements of the …

Read moreDistance of nearest cell having 1 in a binary matrix

BFS for Disconnected Graph

Problem Statement The problem “BFS for Disconnected Graph” states that you are given a disconnected directed graph, print the BFS traversal of the graph. Example The BFS traversal of the graph above gives: 0 1 2 5 3 4 6 Approach Breadth first Search (BFS) traversal for Disconnected Directed Graph …

Read moreBFS for Disconnected Graph

Check given array of size n can represent BST of n levels or not

Problem Statement Given an array with n elements, check given array of size n can represent BST of n levels or not. That is to check whether the binary search tree constructed using these n elements can represent a BST of n levels. Examples arr[] = {10, 8, 6, 9, …

Read moreCheck given array of size n can represent BST of n levels or not

Priority Queue Using Singly Linked List

In priority queue using a singly linked list problem, we need to implement a priority queue by using a singly linked list. A priority queue contains the following operations, push(x, p): Add an element x with priority p at an appropriate position in the priority queue. pop(): Remove and return …

Read morePriority Queue Using Singly Linked List

Reverse String Without Temporary Variable

Problem Statement In the “Reverse String Without Temporary Variable” problem we have given a string “s”. Write a program to reverse this string without using any extra variable or space. Input Format The first line containing the given string “s”. Output Format Print the string which is reverse of the …

Read moreReverse String Without Temporary Variable