Sunidhi Bansal has Published 1100 Articles

Count Subarrays with Consecutive elements differing by 1 in C++

Sunidhi Bansal

Sunidhi Bansal

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

215 Views

We are given an array arr[] containing integers. The goal is to count all subarrays of arr[] such that consecutive elements in each subarray differ by 1 only. If the array is [1, 2, 3] .Subarrays will be [1, 2], [2, 3], [1, 2, 3] only.Let us understand with examples.Input ... Read More

Count subarrays with equal number of 1’s and 0’s in C++

Sunidhi Bansal

Sunidhi Bansal

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

357 Views

We are given an array arr[] containing 0’s and 1’s only. The goal is to count all subarrays of arr[] such that occurrences of 0s and 1s is equal in all. If the array is [1, 0, 0] .Subarray will be [1, 0] only.Let us understand with examples.Input − arr[] ... Read More

Count subarrays with all elements greater than K in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 01-Dec-2020 12:31:47

339 Views

We are given an array arr[] of integers. Also a number K. The goal is to count all subarrays of arr[] such that all elements of the subarray are greater than K or K is less than all elements of the subarrays. If the array is [1, 2, 3] and ... Read More

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

290 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

110 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

804 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

160 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

356 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

158 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

169 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

Advertisements