HackerRank The Story of a Tree Problem Solution

HackerRank The Story of a Tree Problem Solution

One day Bob drew a tree, T, with n nodes and n – 1 edges on a piece of paper. He soon discovered that parent of a node depends on the root of the tree. Learning the fact, Bob invented an exciting new game and decided to play it with Alice. The rules of the … Read more

HackerRank Dijkstra: Shortest Reach 2 Solution

HackerRank Dijkstra: Shortest Reach 2 Problem Solution

In this post, we will solve HackerRank Dijkstra: Shortest Reach 2 Problem Solution. Given an undirected graph and a starting node, determine the lengths of the shortest paths from the starting node to all other nodes in the graph. If a node is unreachable, its distance is -1. Nodes will be numbered consecutively from 1 to n, and … Read more

HackerRank Snakes and Ladders: The Quickest Way Up

HackerRank Snakes and Ladders: The Quickest Way Up Problem Solution

In this post, we will solve HackerRank Snakes and Ladders: The Quickest Way Up Problem Solution. Markov takes out his Snakes and Ladders game, stares at the board and wonders: “If I can always roll the die to whatever number I want, what would be the least number of rolls to reach the destination?”Rules The … Read more

HackerRank Even Tree Problem Solution

HackerRank Even Tree Problem Solution

In this post, we will solve HackerRank Even Tree Problem Solution. You are given a tree (a simple connected graph with no cycles). Find the maximum number of edges you can remove from the tree to get a forest such that each connected component of the forest contains an even number of nodes. As an example, the … Read more

HackerRank Kruskal (MST): Really Special Subtree

HackerRank Kruskal (MST): Really Special Subtree Problem Solution

In this post, we will solve HackerRank Kruskal (MST): Really Special Subtree Problem Solution. Given an undirected weighted connected graph, find the Really Special SubTree in it. The Really Special SubTree is defined as a subgraph consisting of all the nodes in the graph and: To create the Really Special SubTree, always pick the edge … Read more

HackerRank Breadth First Search: Shortest Reach

HackerRank Breadth First Search: Shortest Reach Problem Solution

In this post, we will solve HackerRank Breadth First Search: Shortest Reach Problem Solution. Consider an undirected graph where each edge weighs 6 units. Each of the nodes is labeled consecutively from 1 to n. You will be given a number of queries. For each query, you will be given a list of edges describing … Read more