Programming Articles - Page 1030 of 3363

Program to count good meals with exactly two items in Python

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

312 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

389 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

183 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

481 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

Program to find maximum average pass ratio in Python

Arnab Chakraborty
Updated on 06-Oct-2021 11:35:13

227 Views

Suppose we have a list of classes where classes[i] represents [pass_i, total_i] represents the number of students passed the examination of ith class and total number of students of the ith class respectively. We also have another value extra. This indicates extra number of brilliant students that are guaranteed to pass the exam of any class they are assigned to. We have to assign each of the extra students to a class in a way that maximizes the average number of passed student across all the classes. The pass ratio of a class determined by the number of students of ... Read More

Program to find average waiting time in Python

Arnab Chakraborty
Updated on 06-Oct-2021 11:33:56

825 Views

Suppose we have an array customers, where customers[i] = holds a pair [arrival_i, time_i], here arrival_i is the arrival time of the ith customer. And the arrival times are sorted from less to high. And time_i is the time needed to prepare the order of the ith customer. Now, when a customer arrives, he/she gives the order, and the only that order starts preparing when the cook is idle. The cook does not prepare food for more than one customer at a time. And he prepares in order they were placed their orders. We have to find the average waiting ... Read More

Program to find center of star graph in Python

Arnab Chakraborty
Updated on 06-Oct-2021 11:30:49

598 Views

Suppose we have one undirected star graph with n nodes labeled from 1 to n. As we know a star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node. We have to find the center of the given star graph.So, if the input is likethen the output will be 3 as 3 is at center.To solve this, we will follow these steps −seen := a new setfor each edge (u, v) in graph, doif u is in seen, thenreturn uif v is in seen, ... Read More

Program to find out number of distinct substrings in a given string in python

Arnab Chakraborty
Updated on 06-Oct-2021 11:28:03

992 Views

Suppose, we are given a substring denoted by 's'. We have to find out the unique substrings and return the number of these substrings as output.So, if the input is like s = 'prrstvt', then the output will be 26.The distinct substrings will be −'pr', 'rrs', 'st', 'rr', 'tv', 'rstv', 'stvt', 'prrstv', 'prrstvt', 'rrstvt', 's', 'prrst', 'stv', 'rrstv', 'rst', 'v', 'tvt', 'rstvt', 'r', 'rs', 'vt', 't', 'prr', 'p', 'rrst', and 'prrs'.To solve this, we will follow these steps −visited := a new mapfor each index ind, and value let in s, dotemp := a new setif ind-1 is present in ... Read More

Program to find number of restricted paths from first to last node in Python

Arnab Chakraborty
Updated on 06-Oct-2021 11:26:05

282 Views

Suppose we have one undirected weighted connected graph. The graph has n nodes and they are labelled from 1 to n. A path from start to end is a sequence of nodes like [z0, z1, z2, ..., zk] here z0 is start node and zk is end node and there is an edge between zi and zi+1 where 0

Program to find maximum score we can get in jump game in Python

Arnab Chakraborty
Updated on 06-Oct-2021 11:21:46

735 Views

Suppose we have an array called nums and another value k. We are at index 0. In one move, we can jump at most k steps right without going outside the boundaries of the array. We want to reach the final index of the array. For jumping we get score, that is the sum of all nums[j] for each index j we visited in the array. We have to find the maximum score we can get.So, if the input is like nums = [1, -2, -5, 7, -6, 4] k = 2, then the output will be 10 because, we ... Read More

Advertisements