Found 26504 Articles for Server Side Programming

Program to find out the minimum cost path between the lowest value vertex to the highest value vertex (Python)

Arnab Chakraborty
Updated on 06-Oct-2021 12:44:27

495 Views

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

Program to find out the path between two vertices in a graph that has the minimum penalty (Python)

Arnab Chakraborty
Updated on 06-Oct-2021 12:36:32

357 Views

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

Program to find out the minimum size of the largest clique in a graph (Python)

Arnab Chakraborty
Updated on 06-Oct-2021 12:22:51

224 Views

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

Program to find number of ways to split array into three subarrays in Python

Arnab Chakraborty
Updated on 06-Oct-2021 12:39:56

725 Views

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

Program to find out an MST using Prim's algorithm in Python

Arnab Chakraborty
Updated on 06-Oct-2021 12:19:34

2K+ Views

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

Program to find out the minimum moves in a snakes and ladders game in Python

Arnab Chakraborty
Updated on 06-Oct-2021 12:10:39

979 Views

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

Program to count good meals with exactly two items in Python

Arnab Chakraborty
Updated on 06-Oct-2021 12:10:13

291 Views

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

Program to find maximum number of eaten apples in Python

Arnab Chakraborty
Updated on 06-Oct-2021 11:51:42

359 Views

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

Program to find Reordered Power of 2 in Python

Arnab Chakraborty
Updated on 06-Oct-2021 11:41:39

167 Views

Suppose we have a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is non-zero. We have to check whether we can do this in a way such that the resulting number is a power of 2.So, if the input is like N = 812, then the output will be TrueTo solve this, we will follow these steps −i:= 1while i

Program to find maximum binary string after change in python

Arnab Chakraborty
Updated on 06-Oct-2021 11:38:27

453 Views

Suppose we have a binary string. We can apply each of the following operations any number of times −If the number contains a substring "00", we can replace it with "10".If the number contains a substring "10", we can replace it with "01".Then we have to find the maximum binary (based on its numeric value) string we can get after any number of operations.So, if the input is like s = "001100", then the output will be 111011, because we can transfer them like (00)1100 -> 101(10)0 -> 1010(10) -> 10(10)01 -> 100(10)1 -> 1(00)011 -> 111011.To solve this, we ... Read More

Advertisements