Suppose there are n cities and that are connected with n -1 roads. A city can be visited from any other city. Now the postal system of the cities delivers k letters daily. The letter's destination can be any of the k different cities. A postal worker has to deliver all the letters to their addresses each day. We shall have to find out the minimum distance the worker has to travel to deliver all the letters. The worker can start from any given city.So, if the input is likeand the letters have to be delivered in cities (delv) 1, ... Read More
Suppose we have a special type of graph that has two types of vertices that are named head and feet. The graph has only one head and there are k edges that connect the head to each of the feet. So, if we are given an undirected, unweighted graph; we shall have to find out these special types of graphs in the vertex disjoint subgraphs of the graph. Any two graphs are said to be vertex disjoint if they have no vertex in common.So, if the input is likenumber of nodes (n) = 5, number of feet (t) = 2, ... Read More
Suppose we are given an undirected, weighted graph and are asked to find out the path with the minimum possible travel cost from a particular node to another particular node. The travel cost is calculated as the following: suppose there is a path between vertex A to vertex C as A-> B-> C. The cost of travel from A to B is 10 and the cost of travel from B to C is 20. The cost of travel from A to C will be (cost of traveling from A to B) + (difference of traveling cost from B to C ... Read More
Suppose we have an array called nums, we have to find the number of good ways to split this array nums. Answer may be too large so return result modulo 10^9 + 7. Here a split of an array (with integer elements) is good if the array is split into three non-empty contiguous subarrays respectively from left to right, and the sum of the elements in left side is less than or equal to the sum of the elements in mid part, and the sum of the elements in mid part is less than or equal to the sum of ... Read More
Suppose we are given an undirected, weighted graph and are asked to find out the path with the minimum possible penalty from node a to node b. The penalty of a path is the bitwise OR of the weights of all the edges in the path. So, we must find out such a 'minimum penalty' path, and if there exists no path between the two nodes, we return -1.So, if the input is likestart (s) = 1, end (e) = 3; then the output will be 15.There exist two paths between vertices 1 and 3. The optimal path is 1->2->3, ... Read More
Suppose we are given a graph and are asked to find out the minimum size of the largest clique in the graph. A clique of a graph is a subset of a graph where every pair of vertices are adjacent, i.e. there exists an edge between every pair of vertices. Finding the largest clique in a graph is not possible in polynomial time, so given the number of nodes and edges of a small graph we shall have to find out the largest clique in it.So, if the input is like nodes = 4, edges =4; then the output will ... Read More
Suppose we are given a graph and asked to find out the 'Minimum Spanning Tree' (MST) from that graph. An MST of a graph is a subset of a weighted graph where all the vertices are present and connected, and there exists no cycle in the subset. MST is called minimum because the total edge weight of the MST is the minimum possible from the graph. So, here we use Prim's MST algorithm and find out the total edge weight of the MST from a given graph.So, if the input is like, number of vertices (n) is 4, and start ... Read More
Suppose we are playing a game of snakes and ladders. We have a condition that we can roll any number that we can like on a dice. We start from position 0 and our destination is position 100, and we roll the dice several times to reach the destination. We must find out the least number of dice rolls required to reach the destination if we are provided with the position of the snakes and ladders on the board.The arrays snakes and ladders represent the positions of snakes and ladders in the board and each entry in the arrays contains ... Read More
Suppose we have an array deli where deli[i] is the deliciousness of the ith food, we have to find the number of different good meals we can make from this list. If the answer is too large, then return result modulo 10^9 + 7. Here a good meal means a meal that contains exactly two different food items with a sum of deliciousness which is a power of two. We can select any two different foods to make a good meal.So, if the input is like deli = [1, 7, 3, 6, 5], then the output will be 3 because ... Read More
Suppose we have two arrays called days and apples of same length n. There is a special kind of apple tree that grows apples every day for n consecutive days. On the ith day, it grows apples[i] number of apples and that will rot after days[i] days, so we can say it like that on day i + days[i] the apples will be rotten and cannot be eaten. On some days. If apples[i] = 0, and days[i] = 0, then it indicates on day i, the apple tree is not growing any apple. We can take at most one apple ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP