Sunidhi Bansal has Published 1085 Articles

Count rotations in sorted and rotated linked list in C++

Sunidhi Bansal

Sunidhi Bansal

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

187 Views

We are given a linked list. The list is sorted first and then rotated by K number of nodes. The goal is to find the value of K. If we are given below linked list as input which is rotated by K number of nodes −Then original must have been ... Read More

Count rotations of N which are Odd and Even in C++

Sunidhi Bansal

Sunidhi Bansal

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

176 Views

We are given a number N. The goal is to count the rotations of N that make an odd number and rotations that make an even number. If the number N is 123 its rotations would be 123, 321, 132. The odd rotations are 123 and 321 ( 2 ) ... Read More

Count rows in a matrix that consist of same element in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 01-Dec-2020 12:48:41

845 Views

We are given a matrix consisting of integers. The goal is to find the number of rows in the matrix that have all identical elements in it.If there is 5X4 matrix as shown −15131111115323577777The answer would be 2, row 1 (having all 1’s) and row 3 (having all 7’s) contain ... Read More

Count special palindromes in a String in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 01-Dec-2020 12:43:57

646 Views

We are given a string str. The goal is to count all substrings of str that are special palindromes and have length greater than 1. The special palindromes are strings that have either all the same characters or only the middle character as different. For example if string is “baabaa” ... Read More

Count sub-arrays which have elements less than or equal to X in C++

Sunidhi Bansal

Sunidhi Bansal

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

315 Views

We are given an array arr[] containing integers and a variable X. The goal is to count all subarrays of arr[] such that each subarray contains only elements that are less than or equal to X. For example if array is [1, 2, 3] and X=2 then subarrays will be ... Read More

Count subarrays consisting of only 0’s and only 1’s in a binary array in C++

Sunidhi Bansal

Sunidhi Bansal

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

505 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 each subarray contains only 0’s or only 1’s not both. If the array is [1, 0, 0] .Subarrays will be for 0’s only [0], [0], [0, 0] and ... Read More

Count subarrays having total distinct elements same as original array in C++

Sunidhi Bansal

Sunidhi Bansal

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

225 Views

We are given an array arr[] containing integers. The goal is to count all subarrays of arr[] such that the number of distinct elements in each is the same as the number of distinct elements in the original array. If the original array is [1, 1, 2, 3] then subarrays ... Read More

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

Sunidhi Bansal

Sunidhi Bansal

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

306 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

525 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

473 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

Advertisements