Arnab Chakraborty has Published 4452 Articles

Program to count substrings with all 1s in binary string in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Oct-2021 12:03:47

406 Views

Suppose we have a binary string s. We have to find the number of substrings that contain only "1"s. If the answer is too large, mod the result by 10^9+7.So, if the input is like s = "100111", then the output will be 7, because the substrings containing only "1"s ... Read More

Program to count number of square submatrices in given binary matrix in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Oct-2021 12:01:36

349 Views

Suppose we have a 2D binary matrix. We have to find the total number of square submatrices present in matrix, where all elements are 1.So, if the input is like011011then the output will be 5, because there is one (2 × 2) square, and four (1 × 1) squaresTo solve ... Read More

Program to count number of intervals that is totally contained inside other intervals in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Oct-2021 11:56:48

392 Views

Suppose we have a list of intervals. In this list interval[i] has [start, end] values. We have to find the number of intervals are contained by another interval. If there is an interval that is contained by multiple other intervals that should only be counted once. An interval [s0, e0] ... Read More

Program to find all contiguously increasing numbers in start end range in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Oct-2021 11:54:03

331 Views

Suppose we have two numbers start and end, we have to find a sorted list of integers such that every number e in range [start, end] both inclusive and the digits of e are contiguously increasing. An example of continuously increasing number is 5678, but 169 is not.So, if the ... Read More

Program to count number of ways to win at most k consecutive games in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Oct-2021 10:55:26

249 Views

Suppose we have two numbers n and k. Here n represents the number of games we are going to play. We have to find in how many ways we can win k or fewer games consecutively. If the answer is too large then mod the result by 10^9 + 7.So, ... Read More

Program to find out the number of submatrices from a matrix where the sum of elements is equal to a specific value in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 16-Oct-2021 12:08:35

210 Views

Suppose we are given a matrix that contains integer values. We have to find out the submatrices from the matrix where the sum of elements of the matrices is equal to a given target sum value. We return the number of submatrices.So, if the input is like0010010001011101and target = 5, ... Read More

Program to find out the number of non-zero submatrices in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 16-Oct-2021 12:02:14

366 Views

Suppose we are given a matrix that contains only two values; 1s and 0s. We have to find out the number of submatrices in the given matrix that contains all 1s. We print the value as output.So, if the input is like0010010001011101then the output will be 12.To solve this, we ... Read More

Program to find minimum cost to connect each Cartesian coordinates in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 16-Oct-2021 11:53:51

178 Views

Suppose we have a list of 2D Cartesian coordinate points (x, y). We can connect (x0, y0) and (x1, y1), whose cost is |x0 - x1| + |y0 - y1|. If we are allowed to connect any number of points, we have to find the minimum cost necessary such that ... Read More

Program to sort all elements in a given list and merge them into a string in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 16-Oct-2021 11:24:52

185 Views

Suppose we are given a list of positive integers. We have to sort the list in descending order and then have to join all the elements in it to form a string. We return the joined string.So, if the input is like input = [415, 78, 954, 123, 5], then ... Read More

Program to find a path a continuous path in a rectangular area without engaging a bomb in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 16-Oct-2021 11:20:16

199 Views

Suppose we are given an array mat where the elements are of this form [p, q, r] where p, q are geometric coordinates and r is a radius value. The items in the array are the locations of bombs in a rectangular area of a given width w. The rectangle ... Read More

Advertisements