problem-solution

Shortest path in an unweighted graph

Problem Statement Given the directed, connected and unweighted graph G, a Source and a Destination and the task to find the shortest path possible between two given vertices in the graph. Note: The path does not contain any cycle which means path have finite number of vertices. Example Input Expected Output Path : 0 3 Implementation in …

Shortest path in an unweighted graph Read More »

First Bad Version | Leetcode | Solution

Hi, In this post we will be discussing the first bad version problem present on LeetCode Video Solution Problem Statement You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous …

First Bad Version | Leetcode | Solution Read More »

Replace each element of an array by its corresponding rank

Given an array of n elements, replace each element of the array by its corresponding rank. The rank of the lowest element is 1 and the highest element is n. Take a look at the example given below: Solution The easiest way to solve this problem would be to iterate over the array and store …

Replace each element of an array by its corresponding rank Read More »

Snake and Ladder Problem

Problem statement Given a snake and ladder coordinates which represent the actual snake and ladder board, find the minimum number of dice throws required to reach the destination cell from source cell. This problem can be easily solved bu using 0-1 BFS. Example Input Expected Output Implementation in Python

Topological Sorting

In graph theory, a topological sorting of a directed graph is a linear ordering of vertices of graph such that if there is a directed edge uv from vertex u to vertex v, u comes before v in the ordering. Note: Graph must be directed and acyclic. Example Input Expected Output 0 2 1 3 Pseudocode Implementation in Python

Divide Two Integers | Leet Code

Given two integers dividend and divisor, divide them and output the quotient, without using multiplication, division and mode operator. Note: Both dividend and divisor will be 32-bit signed integers. The divisor will never be 0. Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For …

Divide Two Integers | Leet Code Read More »

Detect Cycle in a Directed Graph

Problem Statement Given the directed, connected and unweighted graph G and the task to check whether the graph contains a cycle or not. Example Input Expected Output No Approach The approach is to use Depth First Traversal to detect a cycle in a Graph. While traversing through the graph if previous node visited node is encountered again …

Detect Cycle in a Directed Graph Read More »

Scroll to Top
[gravityforms id="5" description="false" titla="false" ajax="true"]