Found 7347 Articles for C++

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

94 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

211 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

370 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

111 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

260 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

158 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

Find the Number of Ways to go From One Point to Another in a Grid using C++

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

178 Views

In this article, we are given a question in which we need to find the total number of ways from point A to B where A and B are fixed points, i.e., A is the top-left point in the grid and B is the bottom right point in the grid for example −Input : N = 5 Output : 252 Input : N = 4 Output : 70 Input : N = 3 Output : 20In the given problem, we can formalize the answer by simple observations and get our results.Approach to find The SolutionIn this approach, we ... Read More

Find the Number of Unique Triplets Whose XOR is Zero using C++

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

385 Views

In this article, we will discuss counting the number of unique triplets (x, y, z) in a given array of unique numbers where their XOR is 0. Thus, triplets should be unique where all the three elements are unique and would count all the combinations of triplets for example −Input : arr[ ] = { 5, 6, 7, 1, 3 } Output : 2 Explanation : triplets are { 5, 6, 3 } and { 6, 7, 1 } whose XOR is zero. Input : arr[ ] = { 3, 6, 8, 1, 5, 4 , 12} Output : ... Read More

C++ Remove an Entry Using Value from HashMap while Iterating over It

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

520 Views

Discuss how to remove an entry from HashMap using the value while iterating over it, for exampleInput: HashMap: { 1: “ Mango ”, 2: “ Orange ”, 3: “ Banana ”, 4: “Apple ” }, value=”Banana” Output: HashMap: { 1: “ Mango ”, 2: “ Orange ”, 4: “Apple ” }. Explanation: The third key-value pair is removed using the value “banana”. Input: HashMap: { 1: “Yellow”, 2: “White”, 3: “Green” }, value=”White” Output: HashMap: { 1: “Yellow”, 3: “Green” }.Approach to Find the SolutionIn C++, We can remove the element using the .erase() function. From ... Read More

C++ Remove an Entry Using Key from HashMap while Iterating Over It

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

720 Views

This tutorial will discuss how to remove an entry from HashMap using the key while traversing through it. for example, Input: HashMap: { 1: “Tutorials”,                   2: “Tutorials”,                   3: “Point” }, key=1 Output: HashMap: { 2: “Tutorials”,                    3: “Point” }. Explanation: The first element is removed using key ‘1’. Input: HashMap: { 1: “God”, ... Read More

Advertisements