Found 7197 Articles for C++

Number of jumps required for a thief to cross walls

Riya Kumari
Updated on 12-Jul-2023 12:39:56

294 Views

Imagine a prisoner (or thief) wants to escape from a jail. In order to do so, he needs to cross N number of walls of varying lengths. He can climb X feet for each jump. But, since the walls are slippery, he falls down by Y feet after each jump. So, we need to calculate number of jumps required to cross all the walls. In this article, we will explore different C++ techniques to find the number of jumps required to escape the jail. Input Output Scenarios We have different heights of the N walls in the form of ... Read More

Number of jumps required of given length to reach a point of (d, 0) from origin in 2D plane

Riya Kumari
Updated on 12-Jul-2023 12:35:08

147 Views

In this article, we will discuss the possible solution of an exciting analytical question of how many jumps are required to reach a point (d, 0) from the origin in a 2D plane where you have been specified fixed length of jumps. We will use the fixed length of jumps and the target coordinates to find the minimum number of jumps required. Input Output Scenarios Suppose jump length can be a or b while the target point is (d, 0). Then, the given output is the minimum number of jumps required to reach target. Input: a = 7, b ... Read More

Number of integral solutions for equation x = b*(sumofdigits(x) ^ a)+c

Riya Kumari
Updated on 12-Jul-2023 12:33:41

277 Views

Suppose you are given three integral numbers a, b and c and you have an equation x = b* (sumofdigits(x)^a) +c. Here, sumofdigits(x) is the total sum of all the digits in x. To find all the possible integral solutions which satisfy the equation, we will explore various approaches in C++. Input Output Scenarios Given below are values of a, b and c. Different integral solution which satisfies the equation x = b* (sumofdigits(x)^a) +c is given as output. Input: a = 2, b = 2, c = -3 Output: 125, 447, 575 In the above scenario the ... Read More

Number of horizontal or vertical line segments to connect 3 points

Riya Kumari
Updated on 12-Jul-2023 12:31:43

283 Views

Suppose you are given three different points (or coordinates) and you want to find out number of horizontal or vertical line segments which can be made by connecting those three points. Such line segments together are also known as polyline. You need concepts of computational geometry in order to solve this problem. In this article, we will discuss various approaches in C++ to tackle this problem. Input Output Scenarios Suppose c1, c2 and c3 are coordinates of 3 points in a cartesian plane. The number of horizontal or vertical line segments to connect these 3 points will be given as ... Read More

Number of handshakes such that a person shakes hands only once

Riya Kumari
Updated on 12-Jul-2023 12:29:47

350 Views

Suppose you are in a social gathering. Can you calculate how many handshakes you can do if you were to shakes only once? This question might sound intriguing to you. This can be solved mathematically by using permutations and combinations. However, the mathematical operation might be time-consuming. In this article, we will discuss how to solve such problem using C++. We will explore different approaches which ranges from mathematical formulas, to recursion, and other combinatorial techniques. Input Output Scenarios Suppose you have N number of people in a gathering. You want to calculate the number of handshakes possible ... Read More

Number of elements greater than K in the range L to R using Fenwick Tree (offline queries)

Riya Kumari
Updated on 12-Jul-2023 12:28:27

390 Views

In the field of computer science, we have to process large datasets which includes query selection and update operations. It is a challenging task for the developers to execute these operations in real-time with less time complexity. Using Fenwick tree is an efficient way to tackle these range-based query problems. Fenwick Tree is a data structure which updates elements and calculates the prefix sums of the numbers in a table efficiently. It is also known as Binary Indexed Tree. In this article, we will discuss how to use Fenwick Trees for finding the number of elements greater ... Read More

Number of divisors of product of N numbers

Riya Kumari
Updated on 12-Jul-2023 12:26:49

462 Views

Divisor of a number is which divides it exactly without any remainders. In other words, a divisor of a number n is the one which results in n when multiplied by any other integer. It can also be called as a factor of a number. Dividend ÷ Divisor = Quotient. For example, if we divide 60 with 5 we will get 12 and vice versa therefore, 12 and 60 can be considered as divisors of 60. Number of Divisors of Product of N Numbers Given task is to find the number of divisors of the product of the given ... Read More

Number of divisors of a given number N which are divisible by K

Riya Kumari
Updated on 12-Jul-2023 12:24:02

381 Views

Finding the number of divisors of a given number N which is also divisible by K (any constant number) is a typical mathematical problem which requires lot of calculations. Here, K is usually a number which is less than or equal to square root of N. However, we can construct a C++ program by which counting such numbers will be an easier task. In this article, we will discuss different methods in C++ using which we can find solution to the above given problem. Input Output Scenarios If we consider the below scenario here we have N value as ... Read More

Convert a Binary String to Another by Flipping Prefixes a Minimum Number of Times

Prabhdeep Singh
Updated on 11-Jul-2023 16:24:09

269 Views

Prefixes are the substrings that start from the zeroth index and could be of any size from 1 to the length of the given string. We are given two binary string which means both strings contain only two different types of characters and we have to make the first string equal to the second one by flipping the prefix a minimum number of times. Also, it is given that the length of both of the given strings is equal. Input 1 string str1 = "01100" string str2 = "10101" Output 3 Explanation Only operation that we can perform ... Read More

Largest Roman Numeral Possible by Rearranging Characters of a Given String

Prabhdeep Singh
Updated on 11-Jul-2023 16:07:53

192 Views

The characters represent Roman numbers: 'I', 'V', 'X', 'L', 'C', 'D', and 'M'. We will be given a string that may contain another character also (all the characters will be uppercase English alphabets) and we have to find the largest Roman numerical number possible by altering the position of the characters of the given string, also if it is not possible to get one, then we will return invalid as the answer. Input 1 string str = “VICML” Output MCLVI Explanation In the given string we have M have the greater value followed by the C, and then all ... Read More

Advertisements