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
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
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
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
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
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
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
Given a number N as input. The goal is to find numbers m upto N that satisfy the following condition. Here N
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
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