Found 26504 Articles for Server Side Programming

Count number of paths whose weight is exactly X and has at-least one edge of weight M in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:35:48

188 Views

We are given a tree which can have endless levels, a variable child which will store the number of children a node can have, a variable weight which will store the weight associated with the path and a variable path that will store the path and task is to calculate the count of number of paths which has weights equals to the X and there must be an at least one edge with the given weight.For ExampleInput - int child = 4, weight = 4, path = 4; Output - Count of number of paths whose weight is exactly X and ... Read More

Count of arrays having consecutive element with different values in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:35:13

418 Views

Given three variables size, max_val, last_element as input. The goal is to find the count of different arrays that can be formed in a manner such that they have size elements, have elements between 1 and max_val and the first element is always 1 and the last element is always max_val. Also make sure that no two consecutive elements are the same.Let us understand with examples.For ExampleInput - size = 5, max_val = 3, last_element = 3Output - Count of arrays having consecutive element with different values are: 5Explanation - The arrays will be:-[ 1, 2, 3, 1, 3 ], ... Read More

Count of divisors having more set bits than quotient on dividing N in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:34:33

134 Views

We are given with an integer number let's say, N which is considered as a divisor and it will be divided with the numbers starting from the 1 - N and the task is to calculate the count of those divisors which have more number of set bits than the quotient when divided with the given number N.For ExampleInput - int N = 6Output - Count of divisors having more set bits than quotient on dividing N are: 5Explanation - Firstly, we will divide the number N with the numbers starting from 1 - N and calculate the set bits of ... Read More

Count of cyclic permutations having XOR with other binary string as 0 in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:32:52

669 Views

We are given with two binary strings let's say str_1 and str_2 containing the combination of 1's and 0's and the task is to firstly form the set let's say “SET” of different permutations possible from the string str_1 and then we will perform XOR operations of the elements in set with the binary string str_2 and then check whether the XOR is returning 0 or not. If yes, then consider the case else ignore it.Let us understand with examples.For ExampleInput -  string str_1 = "1111", string str_2 = "1111"Output - Count of cyclic permutations having XOR with other binary string ... Read More

Count of Numbers in a Range where digit d occurs exactly K times in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:31:34

362 Views

We are given with an integer range starting from a variable let's say start till the variable end and a variable k and d. The task is to calculate the count of digits d in a range such that d occurs exactly the k times.For ExampleInput - int start = 10, int end = 100, d = 4 and K = 2Output - Count of Numbers in a Range where digit d occurs exactly K times are: 1Explanation - The range is starting from 10 to 100. So, the possible numbers with digit d i.e. 4 occurs exactly k i.e. 2 ... Read More

Count of Numbers in a Range divisible by m and having digit d in even positions in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:30:57

223 Views

We are given with an integer range, a variable m which is used as divisor and a variable d which is used to check whether the digit 'd' is at even position or not and the task is to calculate the count of those numbers in a range which are divisible by the variable m and have digit d in even positions.For ExampleInput - int start = 20, end = 50, d = 8 and m = 4Output - Count of Numbers in a Range divisible by m and having digit d in even positions are: 2Explanation - The range ... Read More

Count of Numbers in Range where the number does not contain more than K non zero digits in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:28:07

353 Views

We are given an integer range starting from the variable let's say start till the variable end and a variable k and the task is to calculate the count of numbers in the range such that the numbers don't have more than 'k' non-zero digits.For ExampleInput - int start = 50, end = 100 and K = 2;Output - Count of Numbers in Range where the number does not contain more than K non zero digits are: 50Explanation - The range is starting from 50 to 100 and we are given k as 2. As we can see, all the ... Read More

Count of strings that become equal to one of the two strings after one removal in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:26:59

503 Views

We are given with two different strings let's say s1 and s2 and the task is to form the string let's say S by combining the unique letters of s1 and s2 and now check whether after removing one character from the string S it is forming a string which will be equal to string s1 OR s2.For ExampleInput - string S1 = "utter", string S2 = "butter"; Output - Count of strings that become equal to one of the two strings after one removal are: 1Explanation -  we are given with string s1 and s2 and we will from string S ... Read More

Count pairs of non-overlapping palindromic sub-strings of the given string in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:26:27

394 Views

We are given an input as a string, the task is to find out the count of pairs of non-overlapping palindromic sub-strings of the given input string. The value of arr[i][j] is true if the substring is a palindrome, otherwise false. We will take combination out of the string and check if the pairs fulfil the criteria.Let us understand with examples.Input: ABCOutput: Count pairs of non-overlapping palindromic sub-strings is 3Explanation: The possible pairs are (A) (B) (C) ,(A) (BC), (AB) (C), (ABC) Input: ABCDOutput: Count pairs of non-overlapping palindromic sub-strings is 8Explanation: The possible pairs are (A)(B)(C)(D), (A)(B)(CD), (A)(BC)(D), (A)(BCD), (AB)(C)(D), (AB)(CD), (ABC)(D), (ABCD) Approach ... Read More

Count Occurrences of Anagrams in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:21:33

440 Views

We are given an input as a text stream and a word, and the task is to find out the count of occurrences of anagrams of the word in the given text stream. Anagrams are generated by rearranging letters from a word which ends up being a different word or phrase like anagrams of words in a statement "New York Times" can be formed as "Monkeys write".For ExampleInput: String string-:  “workitwrokoffowkr” word = “work”   Output: Count of occurrences of anagram in the string are: 3Explanation: The possible anagrams for the word “work” are work, wrok, rowk, owkr, etc. In the ... Read More

Advertisements