Found 33676 Articles for Programming

Program to find minimum space plane required for skydivers in k days in python

Arnab Chakraborty
Updated on 02-Dec-2020 04:53:37

151 Views

Suppose we have a list of numbers called nums where each value represents a group of people looking to skydive together. And we have another value k representing how many days they can apply for skydiving. We have to find the minimum capacity of the plane we need to be able to fulfill all requests within k days. The requests should be fulfilled in the order they were given and a plane can only fly once a day.So, if the input is like nums = [16, 12, 18, 11, 13], k = 3, then the output will be 28, as ... Read More

Program to find shortest cycle length holding target in python

Arnab Chakraborty
Updated on 02-Dec-2020 04:50:46

400 Views

Suppose we have adjacency list of a directed graph, where each list at index i is represented connected nodes from node i. We also have a target value. We have to find the length of a shortest cycle that contains the target. If there is no solution return -1.So, if the input is liketarget = 3., then the output will be 3, as the cycle is nodes 1 -> 2 -> 3 -> 1. Note there is another cycle 0 -> 1 -> 2 -> 3 -> 0, but this is not shortest.To solve this, we will follow these steps ... Read More

Program to find total cost for completing all shipments in python

Arnab Chakraborty
Updated on 02-Dec-2020 04:47:52

302 Views

Suppose we have a list of lists called ports, where ports[i] represents the list of ports that port i is connected to. We also have another list of lists called shipments where each list of the sequence [i, j] which denotes there is a shipment request from port i to port j. And the cost to ship from port i to port j is the length of the shortest path from the two ports, we have to find the total cost necessary to complete all the shipments.So, if the input is like ports = [[1, 4], [2], [3], [0, 1], ... Read More

Count positive integers with 0 as a digit and maximum ‘d' digits in C++

Sunidhi Bansal
Updated on 01-Dec-2020 13:06:56

134 Views

We are given a number d which represents the number of digits. The goal is to find the count of positive integers with 0 as a digit and have maximum d digits. Count all 1 digit, 2 digit, 3 digit….d digit positive numbers containing at least one 0.We will first find numbers the count of numbers that have d digits with at least one 0. Let’s say d=3. To make a 3-digit number with at least one 0, possible ways are −Here d1 can have 1 to 9 : 9 ways d2 can have 0-9 : 10 ways d3 can ... Read More

Count the number of rhombi possible inside a rectangle of given size in C++

Sunidhi Bansal
Updated on 01-Dec-2020 13:04:39

215 Views

We are given a rectangle with dimensions as height X width. The rectangle is represented on a 2D coordinate system with the left-lower corner at point (0, 0). So the goal is to count the number of rhombi possible inside this rectangle such that all these conditions are met −The rhombus has an area more than 0.The diagonals of the rhombus are parallel to the x and y axis.The rhombus has integer coordinates for all corners.Let us understand with examplesInput − length=3 width=3Output − Count of number of rhombi possible inside a rectangle of given size are: 4Explanation − Below ... Read More

Count Possible Decodings of a given Digit Sequence in C++

Sunidhi Bansal
Updated on 01-Dec-2020 13:02:52

288 Views

We are given a string representing a digit sequence. Each digit is decoded from 1 to 26 as English Alphabet. 1 is ‘A’, 2 is ‘B’ and so on till 26 as ‘Z’. The goal is to find the count of all possible decodings out of a given digit sequence. If the sequence is ‘123’ then possible decodings are ‘ABC’ ( 1-2-3 ), ‘LC’ (12-3), ‘AW’ (1-23). Count is 3.Let us understand with examples.Input − str[]=”1532”Output − Count of Possible Decodings of a given Digit Sequence are − 2Explanation − Possible decodings are AECB - (1-5-3-2) and OCB (15-3-2).Input − ... Read More

Count rotations divisible by 8 in C++

Sunidhi Bansal
Updated on 01-Dec-2020 12:57:52

336 Views

We are given a large number. The goal is to count the rotations of num that are divisible by 8.As the rotations can not be done again and again. We will use the divisible by 8 property. If the last three digits are divisible by 8then the number is divisible by 8. If the number is 1800 then it’s rotations will be 1800, 0180, 0018, 8001 out of 1800 is divisible by 8.Let us understand with examples.Input − num=15320Output − Count of rotations divisible by 4 are: 1Explanation − Rotations are −15320, 01532, 20153, 32015, 53201 Out of these, only ... Read More

Count rotations divisible by 4 in C++

Sunidhi Bansal
Updated on 01-Dec-2020 12:55:38

691 Views

We are given a large number. The goal is to count the rotations of num that are divisible by 4.As the rotations can not be done again and again. We will use the divisible by 4 property. If the last two digits are divisible by 4 then the number is divisible by 4. If the number is 1234 then it’s rotations will be 1234, 4123, 3412, 2341 out of which 3412 will be divisible by 4 as the last two digits 12 is divisible by 4.Let us understand with examples.Input − num=15324Output − Count of rotations divisible by 4 are: ... Read More

Count rotations in sorted and rotated linked list in C++

Sunidhi Bansal
Updated on 01-Dec-2020 12:52:56

188 Views

We are given a linked list. The list is sorted first and then rotated by K number of nodes. The goal is to find the value of K. If we are given below linked list as input which is rotated by K number of nodes −Then original must have been −And we can see K here is 2. Input linked list is a rotation of 2 nodes in the original sorted linked list.Let us understand with examples.Input − List : 5 → 7 → 9 → 1 → 3Output Elements in the linked list are: 5 7 9 1 3Count of ... Read More

Count rotations of N which are Odd and Even in C++

Sunidhi Bansal
Updated on 01-Dec-2020 12:50:06

177 Views

We are given a number N. The goal is to count the rotations of N that make an odd number and rotations that make an even number. If the number N is 123 its rotations would be 123, 321, 132. The odd rotations are 123 and 321 ( 2 ) and even rotation is 132 ( 1 ).Let us understand with examples.Input − N= 54762Output −Count of rotations of N which are Odd are − 2Count of rotations of N which are Even are − 3Explanation − Rotations are −54762, 25476, 62547, 76254, 47625.Even rotations are 3 − 54762, 25476, ... Read More

Advertisements