Found 7347 Articles for C++

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

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

309 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

322 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

Count Strictly Increasing Subarrays in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:19:05

369 Views

We are given an array containing integer elements and the task is to firstly calculate the subarray out of the given array and then check whether the elements in a subarray are in increasing order or not. If yes, then we will consider the subarray else it will be discarded.The approach here is to stop further checking the subarray if the elements in 0th and 1th position are not in increasing order.For Example- in C++Input: int a[] = {1, 7, 5}Output: Count of strictly increasing subarrays is 1Explanation - The possible subarrays include {1, 7, 5}, {1, 7}, {7, 5} where ... Read More

Count numbers in a range having GCD of powers of prime factors equal to 1 in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:18:19

60 Views

Given two numbers start and end representing a range of positive integers. The goal is to find the count of all the numbers that lie in range [start, end] and have prime factorization such that all prime factors of that number have powers such that they have GCD as 1.If a number has prime factorization as 2p * 3q * 5r ….. Then powers p, q, r ...should have gcd=1.Let us understand with examples.For ExampleInput - start = 1, end = 10 Output - Count of numbers in a range having GCD of powers of prime factors equal to 1 are: 6Explanation ... Read More

Count the number of nodes at given level in a tree using BFS in C++

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

959 Views

Given an undirected graph containing the nodes of a tree as vertices. The goal is to find the count of nodes at a given level of the tree using BFS( breadth first search ) algorithm.BFS Algorithm:-This algorithm starts traversing the graph/tree level by level. Starting from node at level 0, it will first traverse all nodes directly connected to it at level 1, then will traverse all nodes at next level and so on.Traverse nodes horizontally at current level.Traverse nodes at the next level in a similar manner.Let us understand with examples.For ExampleInput - level=2Output - Count of number of ... Read More

Count of numbers satisfying m + sum(m) + sum(sum(m)) = N in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:12:54

138 Views

Given a number N as input. The goal is to find numbers m upto N that satisfy the following condition. Here N

Count numbers (smaller than or equal to N) with given digit sum in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:11:42

1K+ Views

Given a string str containing a number and a sum total as input. The goal is to find numbers upto str that have sum of digits equal to total.Let us understand with examples.For ExampleInput - N=”110”  sum=5Output - Count of numbers smaller than or equal to N with given digit sum are: 7Explanation - The numbers upto 110 that have sum of digits equal to 5 are :-5, 14, 23, 32, 41, 50 and 104.Input - N=”1000”  sum=3Output - Count of numbers smaller than or equal to N with given digit sum are: 10Explanation - The numbers upto 1000 that ... Read More

Count sub-matrices having sum divisible 'k' in C++

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

140 Views

Given a row x col matrix as input. The goal is to find all submatrices within the matrix[row][col] such that the sum of elements of that submatrix is divisible by integer k.If the matrix is mat[3][3] and k is 4 then submatrices will be as shown below:- Let us understand with examples.For ExampleInput - matrix[3][3] = { {1, 1, 1}, {2, 2, 2}, {3, 3, 3} }    k=4Output - Count of sub-matrices having sum divisible 'k' are: 4Explanation -  The submatrices will be as shown in above.Input - matrix[3][3] = { {1, 1, 1}, {2, 2, 2 }, {3, 3, ... Read More

Count of Numbers in Range where first digit is equal to last digit of the number in C++

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

391 Views

Given a range of numbers between start and end. The goal is to find the count of numbers that have the first digit equal to the last digit and fall in the range [ first, last ].All single digit numbers will be counted if they lie in the range.Let us understand with examples.For ExampleInput - start = 100, end = 200Output - Count of Numbers in Range where first digit is equal to last digit of the number are: 10Explanation -  The numbers will be:101, 121, 131, 141, 151, 161, 171, 181 and 191.Input - start = 1, end = ... Read More

Count of n digit numbers whose sum of digits equals to given sum in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:05:41

305 Views

Given a positive number as the number of digits and a sum. The goal is to find all d digit numbers that have sum of digits equal to the input sum. The numbers having leading zeros will not be considered as d digit numbers.The ranges are digits between 1 to 100 and sum between 1 and 500.Let us understand with examples.For ExampleInput - digits = 3, digi_sum = 3Output - Count of n digit numbers whose sum of digits equals to given sum are: 6Explanation - Three digit numbers having sum of digits as 3 are:102, 111, 120, 201, 210, ... Read More

Advertisements