Found 7346 Articles for C++

C++ Program to remove Characters from a Numeric String Such That String Becomes Divisible by 8

Prateek Jangid
Updated on 18-May-2022 11:54:33

168 Views

Given a number in the form of a string, we need to find where to make it divisible by eight after deleting zero or more elements. In other words, we need to find whether there is a subsequence of the string, which is divisible by 8. Return the modified string or -1 if it is not possible.Any number whose last three digits are divisible by 8 is also divisible by 8. For example, 56992992 and 476360 are divisible by 8, but 2587788 is not. If the result is a whole number, then the original number is divisible by 8.We can ... Read More

Remove All Nodes Which Don't Lie in Any Path With Sum>=k using C++

Prateek Jangid
Updated on 18-May-2022 11:48:55

141 Views

In this problem, we have a binary tree with a path from the root node to the leaf node that is completely defined. The sum of all nodes from a root node to a leaf node must be greater than or equal to k. So we need to remove all nodes in the paths whose sum is less than k. An important thing to remember here is that a node may be a part of many paths, so only remove such nodes if all the paths have sum < k.From the root node to the leaf node, we can calculate ... Read More

C++ Program to get minimum difference between jigsaw puzzle pieces

Arnab Chakraborty
Updated on 08-Apr-2022 11:50:17

207 Views

Suppose we have an array A with m elements and another number n. Amal decided given a present for his n friend, so he will give each of them a jigsaw puzzle. The shop assistant told him that there are m puzzles in the shop, but they might differ in difficulty and size. Specifically, the ith jigsaw puzzle consists of A[i] pieces. So Amal decided that the difference between the numbers of pieces in his presents must be as small as possible. Let x be the number of pieces in the largest puzzle that he buys and y be the ... Read More

C++ Program to get blocks position after right side rotation

Arnab Chakraborty
Updated on 08-Apr-2022 11:47:30

134 Views

Suppose we have an array A with n elements. A[i] represents there are A[i] number of blocks stacked on top of each other at ith column. The entire blocks are inside a closed transparent boundary box. Now if we rotate the entire big box clockwise 90°, then due to change of gravity direction, the blocks will fall, after than reverse it to its previous orientation. Then find the new array like A after these operations.Problem CategoryThis problem falls under sorting problems. Sorting is a very common problem while we are talking about different problem solving algorithms in computer science. As ... Read More

C++ Program to find length of maximum non-decreasing subsegment

Arnab Chakraborty
Updated on 08-Apr-2022 11:44:14

599 Views

Suppose we have an array A with n elements. Amal has decided to make some money doing business on the Internet for exactly n days. On the i-th day he makes A[i] amount of money. Amal loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence A[i]. The subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the nondecreasing order.Problem CategoryAn array in the data structure is a finite collection of elements of a specific type. Arrays are used to ... Read More

C++ Program to get number at position k after positioning n natural numbers

Arnab Chakraborty
Updated on 08-Apr-2022 11:41:50

208 Views

Suppose we have two numbers n and k. We are determined to rearrange natural numbers. But there are too many natural numbers, so we have decided to start with the first n. Pick the following sequence of numbers: firstly, all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). We have to find which number will stand at the position number k.Problem CategoryVarious problems in programming can be solved through different techniques. To solve a problem, we have to devise an algorithm first, and to do that we ... Read More

C++ Program to check joke programming code is generating output or not

Arnab Chakraborty
Updated on 08-Apr-2022 11:39:37

136 Views

Suppose we have a string S with n characters. In a joke programming language, there are only 4 instructions."H" to print "Hello World""Q" to print its source code"9" to print "99 bottles of juice""+" to increment the value stored in accumulatorInstructions "H" and "Q" are case-sensitive and they must be in uppercase. The characters except these four are ignored. We have a program written in this language. You have to check whether executing this program will produce any output or not.Problem CategoryVarious problems in programming can be solved through different techniques. To solve a problem, we have to devise an ... Read More

C++ Program to check player position is dangerous or not in football match

Arnab Chakraborty
Updated on 08-Apr-2022 11:36:50

315 Views

Suppose we have a binary string S of size n. Amal loves football very much. One day, he was watching a match, he was writing the players' current positions on a piece of paper. The given string is the written position. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is marked as "dangerous". We have to check whether it is dangerous or not.Problem CategoryTo solve this problem, we need to manipulate strings. Strings in a ... Read More

C++ Program to check April fool news is fake or real

Arnab Chakraborty
Updated on 08-Apr-2022 11:34:14

155 Views

Suppose we have a string S with n characters. As it's the first of April, Amal is suspecting that the news she reads today are fake, and he does not want to look silly in front of all the contestants. He knows that a news is fake if it contains "fool" as a subsequence. We have to check whether the news is really fake or not.Problem CategoryTo solve this problem, we need to manipulate strings. Strings in a programming language are a stream of characters that are stored in a particular array-like data type. Several languages specify strings as a ... Read More

C++ Program to get minimum perimeter of rectangle whose area is n

Arnab Chakraborty
Updated on 08-Apr-2022 11:31:27

259 Views

Suppose we have a number n. We are developing a project to build a new data center. The plot of this data center will be a rectangle with an area of exactly n square meters. Each side of the data center must be an integer. We want to minimize the impact of the external environment on the data center. For this reason, we want to minimize the length of the perimeter of the data center (that is, the sum of the lengths of its four sides). We have to find the minimum perimeter of a rectangular data center with an ... Read More

Advertisements