Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 53 of 377

Program to find dropped correct sensor value from the faulty list in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 149 Views

Suppose we have two lists nums1 and nums2, they are representing sensor metrics. Each list contains unique values, so a ≠ b. One of these two lists are holding accurate sensor metrics but the other one contains faulty. In the faulty list one value, that is not the last value was dropped and a wrong value was placed to the end of that list. We have to find the actual value that was dropped.So, if the input is like nums1 = [5, 10, 15] nums2 = [10, 15, 8], then the output will be 5, as first list nums1 holds ...

Read More

Program to count number of ways ball can drop to lowest level by avoiding blacklisted steps in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 265 Views

Suppose we have a value h and a list of numbers called blacklist. We are currently at height h, and are playing a game to move a small ball down to height 0. Now, in even rounds (starting from 0) we can move the ball 1, 2, or 4 stairs down. And in odd rounds, we can move the ball 1, 3, or 4 stairs down. Some levels are blacklisted. So if the ball reach there, it will die immediately. We have to find the number of ways the ball can move down at height 0. If the answer is ...

Read More

Program to count number of operations needed to make string as concatenation of same string twice in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 215 Views

Suppose we have a lowercase string s. Now consider an operation, where we can delete, insert or update any character in s. We have to count minimum number of operations required to make s = (t concatenate t) for any string t.So, if the input is like s = "pqrxqsr", then the output will be 2, because, we can update the "x" with "p" and delete "s", then s is "pqrpqr", this is s = t concatenate t, for t = "pqr".To solve this, we will follow these steps −Define a function edit_distance(). This will take s1, s2m := size ...

Read More

Program to find length of smallest sublist that can be deleted to make sum divisible by k in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 235 Views

Suppose we have a list with positive values, called nums and also have a positive number k. We have to find the length of the shortest sublist (may be empty) that we can delete from nums, such that sum of the remaining elements is divisible by k. But we cannot remove the entire list. If there is no such sublist to delete, return -1.So, if the input is like nums = [5, 8, 6, 3] k = 8, then the output will be 1, because current sum of the elements of [5, 8, 6, 3] is 22. If we remove ...

Read More

Program to find minimum deletions to make strings strings in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 630 Views

Suppose we have two lowercase strings s and t, now consider an operation where we can delete any character in any of these two strings. We have to find the minimum number of operations needed to make s and t equal.So, if the input is like s = "pipe" t = "ripe", then the output will be 2, because we can delete "p" from s and "r" from t to make these strings same "ipe"To solve this, we will follow these steps −m := size of sn := size of tDefine a function dp() . This will take i, jif ...

Read More

Program to find maximum profit after cutting rods and selling same length rods in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 545 Views

Suppose we have a list of rod lengths called rodLen. We also have another two integers called profit and cost, represents profit per length and cost per cut. We can make gain profit per unit length of a rod but we can only sell rods that are all of the same length. We can also cut a rod into two pieces such that their lengths are integers, but we have to pay cost amount for each cut. We can cut a rod as many times as we want. We have to find the maximum profit that we can make.So, if ...

Read More

Program to find maximum length of k ribbons of same length in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 1K+ Views

Suppose we have a list of positive numbers, representing ribbons length and also have one value k. We can cut the ribbons as many times as we want, we have to find the largest length r such that we can have k ribbons of length r. If we cannot find such solution, return -1.So, if the input is like ribbons = [1, 2, 5, 7, 15] k = 5, then the output will be 5, as we can cut the ribbon of size 15 into 3 pieces of length 5 each. Then cut the ribbon of size 7 into size ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 598 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 are ["1", "1", "1", "1", "11", "11" and "111"]To solve this, we will follow these steps −a := 0count := 0for i in range 0 to size of s - 1, doif s[i] is same as "0", thena := 0otherwise, a := a + 1count := count + areturn countExampleLet ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 497 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 this, we will follow these steps −if mat is empty, thenreturn 0c := 0for i in range 0 to row count of mat, dofor j in range 0 to column count of mat, doif mat[i, j] is 1, thenif i is 0 or j is 0, thenc := c + ...

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 600 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] is inside another interval [s1, e1] when s0 ≤ s1 and e0 ≥ e1.So, if the input is like intervals = [[2, 6], [3, 4], [4, 7], [5, 5]], then the output will be 2, because [3, 4] and [5, 5] are inside [2, 6] and [4, 7] respectively.To solve ...

Read More
Showing 521–530 of 3,768 articles
« Prev 1 51 52 53 54 55 377 Next »
Advertisements