Found 26504 Articles for Server Side Programming

Represent a Number as Sum of Minimum Possible Pseudo-Binary Numbers in C++

Prateek Jangid
Updated on 26-Nov-2021 06:46:41

638 Views

This tutorial will discuss the representation of a number as a sum of minimum pseudo-binary numbers. Pseudo-binary numbers are the numbers that consist of only binary digits, i.e., 0 and 1. Examples of pseudo-binary numbers are 00, 11, 10, 100, 111, 1011, etc.Below are some examples of numbers represented as the sum of pseudo-binary numbers.Input : 23 Output : 11 + 11 + 1 Explanation : 23 = 11 + 11 + 1, sum of pseudo-binary numbers(11, 11, 1) is 23. Input : 50 Output : 10 + 10 + 10 + 10 + 10Approach to Find the SolutionBelow ... Read More

Represent a number as a Sum of Maximum Possible Number of Prime Numbers in C++

Prateek Jangid
Updated on 26-Nov-2021 06:43:01

275 Views

Discuss a problem where we are given a number N, and we need to split this number in the maximum prime numbers sum, for exampleInput: N = 7 Output: 2 2 3 Explanation: 7 can be represented as the sum of two 2’s and a 3 which are the maximum possible prime numbers. Input : N = 17 Output: 2 2 2 2 2 2 2 3Approach to Find the SolutionTo represent a number in prime numbers, we can subtract a prime number with N and check the difference for prime. If the difference is prime, then we can ... Read More

Find the Numbers that are not divisible by any number in the range [2, 10] using C++

Prateek Jangid
Updated on 26-Nov-2021 06:51:33

886 Views

In this article, we will discuss the problem to find the numbers from 1 to n(given) which are can not be divided by any number from 2 to 10. Let's understand this with some examples −Input : num = 14 Output : 3 Explanation: There are three numbers, 1, 11, and 13, which are not divisible. Input : num = 21 Output : 5 Explanation: There are five numbers 1, 11, 13, 17, and 19, which are not divisible.Approach to find The SolutionSimple ApproachIf we check every number from 1 to num, whether it can be divided by any ... Read More

Represent a Given Set of Points by the Best Possible Straight Line in C++

Prateek Jangid
Updated on 26-Nov-2021 06:40:23

442 Views

Discuss How to represent a set of points by the best possible straight line. We are given values (x, y) of a set of points, and we need to find the best straight line y = mx + c, So all we need is to find the value of m and c, for exampleInput: no_of_points = 4 x1 = 2, y1 = 3, x2 = 5, y2 = 6, x3 = 1, y3 = 3, x4 = 4, y4 = 5. Output: m = 0.8, c = 1.85 Explanation: If we apply the value of m and c in ... Read More

Find the number with set bits only between L-th and R-th index using C++

Prateek Jangid
Updated on 26-Nov-2021 06:39:11

147 Views

In the given problem we need to find the value of a number which has all of the set bits between the given range L, R. For example −Input: L = 1, R = 5 Output: 62 Explanation: representation of given L and R in binary form is 0..0111110 Input: L = 1, R = 4 Output: 30 Explanation: representation of given L and R in binary form is 0..11110Approach to find The SolutionIn the given problem, we are going to discuss two approaches, Brute Force and Efficient Approach.Brute ForceIn this approach, we are simply going to traverse through ... Read More

Function for Removing Forbidden Characters in C++

Prateek Jangid
Updated on 26-Nov-2021 06:32:58

276 Views

Discuss the way to remove functions that will remove forbidden characters like [ ‘ : ’, ‘ ? ‘, ‘ \ ’, ‘ / ’, ‘ < ’, ‘ > ’, ‘ | ’, ‘ * ’ ] from a string, for exampleInput: str = “ Hello: Welco*me/ to Tu>torials point|. ” Output: “ Hello Welcome to Tutorials point. ” Explanation: Input String contains forbidden characters which got removed and new string has no forbidden characters. Input: str = “ How/ are y*ou doi, ng? ” Output: “ How are you doing ”Approach to Find the SolutionA simple approach ... Read More

Remove One Bit from a Binary Number to Get Maximum Value in C++

Prateek Jangid
Updated on 26-Nov-2021 06:30:28

520 Views

Discuss a problem in which we are given a binary number. We have to remove a bit from it so that the remaining number should be the maximum of all the other options, for exampleInput : N = 1011 Output: 111 Explanation: We need to remove one bit so removing 0 bit will give a maximum number than removing any 1’s bit. 111 > 101, 011. Input: 111 Output: 11 Explanation: Since all the bits are 1 so we can remove any bit.Approach to Find the SolutionBrute-Force MethodApplying brute force will give the maximum resultant number, i.e., by removing ... Read More

C++ Remove Nodes on Root to Leaf Paths of Length < K

Prateek Jangid
Updated on 26-Nov-2021 06:27:10

176 Views

Given a tree, and we need to remove the leaf node of the path having a length less than the given k, for example.Input −K = 4.Output −ExplanationThe paths were : 1. A -> B -> C -> E length = 4 2. A -> B -> C -> F length = 4 3. A -> B -> D length = 3 4. A -> G -> H length = 3 5. A -> B -> I length = 3 Now as you can see paths 3, 4, 5 have length of 3 which is less than given k so ... Read More

Find the Number With Even Sum of Digits using C++

Prateek Jangid
Updated on 26-Nov-2021 06:32:41

431 Views

An integer number that can be completely divided by 2 is an even number. So in this article we are given the number n, and we need to find the nth number with an even sum of digits. The First five numbers with an even sum of digits are 2, 4, 6, 8, and 11. For example −Input : n = 5 Output : 11 Explanation : First 5 numbers with even sum of digits are 2, 4, 6, 8, 11 i.e 5th number is 11. Input : 12 Output : 24Approach to find The SolutionNow you will get ... Read More

C++ Remove Invalid Parentheses from an Expression

Prateek Jangid
Updated on 26-Nov-2021 06:23:33

247 Views

Given a parentheses sequence; now, you have to print all the possible parentheses that it can make by removing the invalid brackets, for exampleInput : str = “()())()” - Output : ()()() (())() There are two possible solutions "()()()" and "(())()" Input : str = (v)())() Output : (v)()() (v())()In this problem, we are going to use backtracking so that it will print all the valid sequences.Approach to Find the SolutionIn this approach, we will be trying to remove the opening and closing brackets one by one using BFS. Now for each sequence, we check if it is valid ... Read More

Advertisements