Arnab Chakraborty has Published 4452 Articles

Program to count submatrices with all ones using Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-May-2021 12:59:14

438 Views

Suppose we have m x n binary matrix, we have to find how many submatrices have all ones.So, if the input is like101011011then the output will be 13 as there are 6 (1x1) matrices, 3 (2, 1) matrices, 2 (1x2) matrices, 1 (3x1) matrix and 1 (4x4) matrix.To solve this, ... Read More

Program to find range sum of sorted subarray sums using Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-May-2021 12:58:22

290 Views

Suppose we have an array nums with n positive elements. If we compute the sum of all non-empty contiguous subarrays of nums and then sort them in non-decreasing fashion, by creating a new array of n*(n+1)/2 numbers. We have to find the sum of the numbers from index left to ... Read More

Program to find minimum difference between largest and smallest value in three moves using Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-May-2021 12:57:41

571 Views

Suppose we have an array called nums. We can change one element from this array to any value in one move. We have to find the minimum difference between the largest and smallest value of nums after preforming at most 3 moves.So, if the input is like nums = [3, ... Read More

Program to find number of substrings with only 1s using Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-May-2021 12:57:04

117 Views

Suppose we have a binary string s. We have to find the number of substrings with all characters 1's. The answer may be very large so return result mod 10^9 + 7.So, if the input is like s = "1011010", then the output will be 5 because 1. four times ... Read More

Program to find path with maximum probability using Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-May-2021 12:56:07

387 Views

Suppose we have an undirected weighted graph with n nodes (nodes are numbered from 0 onwards), This graph is given as input using edge list, for each edge e, it has a probability of success of traversing that edge probability[e]. We also have start and end nodes, we have to ... Read More

Program to find number of nodes in the sub-tree with the same label using Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-May-2021 12:54:53

354 Views

Suppose we have a rooted general tree with n nodes, whose nodes are numbered from 0 to n-1. Each node has a label with lowercase English letter. The labels are given as input in labels array, where lables[i] contains label for ith node. The tree is represented by edge list ... Read More

Program to find number of sub-arrays with odd sum using Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-May-2021 12:53:52

140 Views

Suppose we have an array arr. We have to find the number of sub-arrays with odd sum. If the answer is too large then return result modulo 10^9+7.So, if the input is like arr = [8, 3, 7], then the output will be 3 because all sub arrays are [[8], ... Read More

Program to find number of good ways to split a string using Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-May-2021 12:51:55

277 Views

Suppose we have a string s. Now a split is said to be a good split when we can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the equal. We have ... Read More

Program to add two polynomials given as linked lists using Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 28-May-2021 14:04:57

2K+ Views

Suppose, we are given two polynomials and we have to find out the addition of the two polynomials. The polynomials have to be represented as linked lists; the terms of the polynomials will be represented as a linked list node. Each linked list node will contain the coefficient value, power ... Read More

Program to build and evaluate an expression tree using Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 28-May-2021 14:03:32

2K+ Views

Suppose, we are given the post order traversal of an expression tree. We have to build an expression tree from the given post-order traversal, and then evaluate the expression. We return the root of the expression tree and the evaluated value of the tree.So, if the input is likethen the ... Read More

Advertisements