C++ Code to Find How Long TVs Are On to Watch a Match

Arnab Chakraborty
Updated on 30-Mar-2022 12:48:26

192 Views

Suppose we have an array A with n elements. Amal wants to watch a match of 90 minutes and there is no break. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Amal immediately turns off the TV. There will be n interesting minutes represented by the array A. We have to calculate for how many minutes Amal will watch the game.So, if the input is like A = [7, 20, 88], then the output will be 35, because after 20, he will still watch the game till 35, then turn off it.StepsTo solve ... Read More

Count Number of Packs of Sheets to be Bought in C++

Arnab Chakraborty
Updated on 30-Mar-2022 12:45:28

183 Views

Suppose we have four numbers k, n, s and p. To make a paper airplane, Rectangular piece of papers are used. From a sheet of standard size we can make s number of airplanes. A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the other people. Each person should have enough sheets to make n different airplanes. We have to count the number of packs should we buy?So, if the input is like k = 5; n ... Read More

Find Screen Size with n Pixels in C++

Arnab Chakraborty
Updated on 30-Mar-2022 12:42:37

570 Views

Suppose we have a number n. In a display there will be n pixels. We have to find the size of rectangular display. The rule is like below −The number of rows (a) does not exceed number of columns (b) [a

C++ Code to Calculate Number of Standing Spectators at Time T

Arnab Chakraborty
Updated on 30-Mar-2022 12:37:28

191 Views

Suppose we have three numbers n, k and t. Amal is analyzing Mexican waves. There are n spectators numbered from 1 to n. They start from time 0. At time 1, first spectator stands, at time 2, second spectator stands. At time k, kth spectator stands then at time (k+1) the (k+1) th spectator stands and first spectator sits, at (k+2), the (k+2)th spectator stands but 2nd one sits, now at nth time, nth spectator stands and (n-k)th spectator sits. At time (n+1), the (n+1-k)th spectator sits and so on. We have to find the number of spectators stands at ... Read More

Count Number of Times Stones Can Be Given in C++

Arnab Chakraborty
Updated on 30-Mar-2022 12:35:34

223 Views

Suppose we have a number n. Amal gives some stones to Bimal and he gives stones more than once, but in one move if Amal gives k stones, in the next move he cannot give k stones, so given stones in one move must be different than the previous move. We have to count the number of times Amal can give stones to Bimal.So, if the input is like n = 4, then the output will be 3, because 1 stone then 2 stones then again 1 stones.StepsTo solve this, we will follow these steps −return (n * 2 + ... Read More

C++ Code to Find How Long a Person Will Live Between Presses

Arnab Chakraborty
Updated on 30-Mar-2022 12:33:35

121 Views

Suppose we have four numbers d, L, v1 and v2. Two presses are initially at location 0 and L, they are moving towards each other with speed v1 and v2 each. The width of a person is d, he dies if the gap between two presses is less than d. We have to find how long the person will stay alive.So, if the input is like d = 1; L = 9; v1 = 1; v2 = 2;, then the output will be 2.6667StepsTo solve this, we will follow these steps −e := (L - d)/(v1 + v2) return eExampleLet ... Read More

Minimum Jumps to Reach Home by Frog in C++

Arnab Chakraborty
Updated on 30-Mar-2022 12:30:48

433 Views

Suppose we have one binary string S with n bits and another number d. On a number line, a frog wants to reach point n, starting from the point 1. The frog can jump to the right at a distance not more than d. For each point from 1 to n if there is a lily flower it is marked as 1, and 0 if not. The frog can jump only in points with a lilies. We have to find the minimal number of jumps that the frog needs to reach n. If not possible, return -1.So, if the input ... Read More

C++ Code to Count Maximum Groups Can Be Made

Arnab Chakraborty
Updated on 30-Mar-2022 12:27:18

420 Views

Suppose we have an array A with n elements. There were n groups of students. A group is either one person who can write the code with anyone else, or two people who want to write the code in the same team. But the mentor decided to form teams of exactly three people. We have to find the maximum number of teams of three people the mentor can form. For groups of two, either both students should write the code, or both should not. If two students from a group of two will write the code, they should be in ... Read More

Iterate Over a HashMap in Java

AmitDiwan
Updated on 30-Mar-2022 09:08:14

477 Views

In this article, we will understand how to iterate over a HashMap. Java HashMap is a hash table based implementation of Java's Map interface. It is a collection of key-value pairs.Below is a demonstration of the same −Suppose our input is −Input Hashmap: {Java=Enterprise, JavaScript=Frontend, Mysql=Backend, Python=ML/AI}The desired output would be −The keys of the Hashmap are: Java, JavaScript, Mysql, Python, The Values of the Hashmap are: Enterprise, Frontend, Backend, ML/AI, AlgorithmStep 1 - START Step 2 - Declare namely Step 3 - Define the values. Step 4 - Create a hashmap of strings and initialize elements in it using ... Read More

Convert LinkedList to Array and Vice Versa in Java

AmitDiwan
Updated on 30-Mar-2022 08:20:05

427 Views

In this article, we will understand how to convert the linked list into an array and vice versa. The java.util.LinkedList class operations perform we can expect for a doubly-linked list. Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.Below is a demonstration of the same −Suppose our input is −The list is defined as: [Java, Python, Scala, Mysql]The desired output would be −The result array is: Java Python Scala MysqlAlgorithmStep 1 - START Step 2 - Declare namely Step 3 - Define the values. Step 4 ... Read More

Advertisements