Sunidhi Bansal has Published 1085 Articles

Count subarrays with equal number of occurrences of two given elements in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 01-Dec-2020 12:29:54

402 Views

We are given an array arr[] of integers. Also, two numbers A and B. The goal is to count all subarrays of arr[] such that occurrences of A and B is equal in all. If the array is [1, 2, 3] and A is 1 and B is 2. Subarrays ... Read More

Count the number of words having sum of ASCII values less than and greater than k in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 01-Dec-2020 12:27:52

171 Views

We are given a string str with a sentence and a number k. The goal is to find the count of in str that have ascii value less than k and words with ascii value greater than k.ASCII − Unique code as the number assigned to each character in a ... Read More

Count total number of digits from 1 to N in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 01-Dec-2020 12:25:17

1K+ Views

We are given a number N as input. The goal is to count the total number of digits between numbers 1 to N. 1 to 9 numbers require 1 digit each, 11 to 99 require 2 digits each, 100 to 999 require 3 digits each and so on.Let us understand ... Read More

Count subarrays with Prime sum in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 01-Dec-2020 12:22:09

257 Views

We are given an array of positive integers. The goal is to find the subarrays of numbers in an array such that each subarray has the sum as prime. If the array is { 1, 2, 3, 4 }. Then subarrays will be {1, 2}, {2, 3}, {3, 4}. Count ... Read More

Count subarrays with same even and odd elements in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 01-Dec-2020 12:20:20

464 Views

We are given an array of positive integers. The goal is to find the subarrays of numbers in an array such that each subarray has the same number of even and odd elements in it. If the array is { 1, 2, 3, 4 }. Then subarrays will be {1, ... Read More

Count subsequence of length three in a given string in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 01-Dec-2020 12:18:03

232 Views

We are given string str and a substring sub_str of length 3. The goal is to find the count of subsequence sub_str in str. Example “act” is thrice in “cataract” ( cataract, cataract, cataract ).Let us understand with examples.Input − str= “settlement” sub_str=”set”Output − Count of a subsequence of length ... Read More

Count subsets having distinct even numbers in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 01-Dec-2020 12:16:00

253 Views

We are given an array of positive integers. The goal is to find the subsets of numbers in an array such that each subset has distinct even numbers in it. All sets with the same elements will be counted as 1. [2, 4, 6] and [6, 2, 4] are the ... Read More

Count substrings that starts with character X and ends with character Y in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 01-Dec-2020 12:14:35

463 Views

We are given string str. The goal is to count the number of substrings in str that have starting character same as character X and ending character same as character Y. For example, if input is “artact” and X=’a’ and Y=’t’, the substrings will be “art”, “act”, “artact”. The count ... Read More

Count substrings with each character occurring at most k times in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 01-Dec-2020 12:12:50

346 Views

We are given a string str. The goal is to count the number of substrings in str that have each character occurring utmost k times. For example if input is “abc” and k=1, the substrings will be “a”, “b”, “c”, “ab”, “bc”, “abc”.Let us understand with examples.Input − str=”abaefgf”Output − ... Read More

Count substrings with same first and last characters in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 01-Dec-2020 12:10:08

534 Views

We are given a string str. The goal is to count the number of substrings in str that have the same starting and ending character. For example, if input is “baca” substrings will be “b”, “a”, “c”, “a”, “aca”. Total 5.Let us understand with examples.Input − str=”abaefgf”Output −Count of substrings ... Read More

Advertisements