Arnab Chakraborty has Published 4293 Articles

Clumsy Factorial in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 07:49:18

2K+ Views

As we know that the factorial of a positive integer n is the product of all positive integers less than or equal to n. So factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1. We will try to ... Read More

Max Consecutive Ones III in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 07:45:44

575 Views

Suppose we have an array A of 0s and 1s, we can update up to K values from 0 to 1. We have to find the length of the longest (contiguous) subarray that contains only 1s. So if A = [1, 1, 1, 0, 0, 0, 1, 1, 1, 1, ... Read More

Subarray Sums Divisible by K in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 07:42:38

508 Views

Suppose we have an array A of integers. We have to find the number of contiguous non-empty subarray, that have a sum divisible by k. If A = [4, 5, 0, -2, -3, 1] and k = 5, then the output will be 7. There are seven subarrays. [[4, 5, ... Read More

Minimum Falling Path Sum in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 07:40:40

279 Views

Suppose we have a square array of integers A, we want the minimum sum of a falling path through A. Falling path is basically a path that starts at any element in the first row, and chooses one element from each row. And the next row's element must be in ... Read More

Minimum Add to Make Parentheses Valid in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 07:38:19

403 Views

Suppose we have a string S of '(' and ')' parentheses, we add the minimum number of parentheses at any positions, so that the resulting parentheses string is valid. A parentheses string is valid if and only if −It is the empty stringIt can be written as XY (X concatenated ... Read More

Fruit Into Baskets in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 07:35:38

1K+ Views

Suppose we have a row of trees, the i-th tree produces fruit with type tree[i]. we can start at any tree of our choice, then repeatedly perform these steps −Add one piece of fruit from this tree to our baskets. If there is no chance, then stop.Move to the next ... Read More

Online Stock Span in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 07:33:05

200 Views

Suppose we have an API, that collects daily price quotes for some stock, and returns the span of that stock's price for the current day. Here the span of the stock's price today is defined as −The maximum number of consecutive days (starting from today and going backwards) where the ... Read More

Find and Replace Pattern in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 07:29:54

190 Views

Suppose we have a list of words and a pattern, and we have to find which words in words matches the pattern. Here a word matches the pattern if there exists a permutation of letters p so that after replacing every letter x in the pattern with p(x), we get ... Read More

Design A Leaderboard in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 06:59:12

1K+ Views

Suppose we have to design a Leaderboard class, there are three different functions −addScore(playerId, score) − This will update the leaderboard by adding score to the given player's score. When there is no such player with given id in the leaderboard, add him to the leaderboard with the given score.top(K) ... Read More

Longest Arithmetic Subsequence of Given Difference in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 06:49:02

442 Views

Suppose we have an integer array arr and an integer difference, we have to find the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence is same as the difference. So if the input is like [1, ... Read More

Advertisements