Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 50 of 377

Check if frequency of each digit is less than the digit in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 182 Views

Suppose we have a number n, we have to check whether the occurrence of each digit of n is less than or equal to digit itself.So, if the input is like n = 5162569, then the output will be True as the digits and frequencies are (5, 2), (1, 1), (6, 2) and (9, 1), for all the frequency is either small or equal to the digit value.To solve this, we will follow these steps −for i in range 0 to 9, dotemp := n, cnt := 0while temp is non-zero, doif temp mod 10 is same as i, thencnt ...

Read More

Program to check some elements in matrix forms a cycle or not in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 269 Views

Suppose we have a 2d matrix. We have to check whether we can start from some cell then move adjacent cells (up, down, left, right) of the same value, and come back to the same starting point. We cannot revisit a cell that we have visited last.So, if the input is like222121212221then the output will be True, as we can follow 2s to form a cycle.To solve this, we will follow these steps −R := row count of matrixC := column count of matrixvis := make a matrix of size R x C and fill with FalseDefine a function dfs() ...

Read More

Program to find largest average of sublist whose size at least k in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 345 Views

Suppose we have a list of numbers called nums and another value k, we have to find the largest average value of any sublist of the list whose length is at least k.So, if the input is like nums = [2, 10, -50, 4, 6, 6] k = 3, then the output will be 5.33333333, as sublist [4, 6, 6] has the largest average valueTo solve this, we will follow these steps −left := minimum of nums, right := maximum of numss := sum of all numbers in nums from index 0 to k − 1largest_avg := s / kwhile left

Read More

Program to check number of requests that will be processed with given conditions in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 517 Views

Suppose we have a list of requests where each list contains elements like [uid, time_sec] (uid is the user id and time_sec is the timestamp). This indicates the user whose id is uid has requested to a website at timestamp time_sec. We also have two values u and g where u denotes maximum number of requests that are allowed in any < 60 second frame for a given uid and g is the maximum number of requests that are allowed in any < 60 second frame globally. Now if we want to process each request one by one and rate ...

Read More

Check if given array is almost sorted (elements are at-most one position away) in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 468 Views

Suppose we have an array of numbers called nums, where all elements are unique. We have to check whether nums is almost sorted or not. As we know an array is almost sorted when any of its elements can occur at a maximum of 1 distance away from its original position in the sorted array.So, if the input is like nums = [10, 30, 20, 40], then the output will be True as 10 is placed at its original place and all other elements are at max one place away from their actual position.To solve this, we will follow these ...

Read More

Check if given four integers (or sides) make rectangle in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have a list of four sides, we have to check whether these four sides are forming a rectangle or not.So, if the input is like sides = [10, 30, 30, 10], then the output will be True as there are pair of sides 10 and 30.To solve this, we will follow these steps −if all values of sides are same, thenreturn Trueotherwise when sides[0] is same as sides[1] and sides[2] is same as sides[3], thenreturn Trueotherwise when sides[0] is same as sides[3] and sides[2] is same as sides[1], thenreturn Trueotherwise when sides[0] is same as sides[2] and sides[3] ...

Read More

Program to find maximum adjacent absolute value sum after single reversal in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 228 Views

Suppose we have a list of numbers called nums and we can reverse any sublist in the list at most once. After performing this operation, we have to find the maximum possible value of$\displaystyle\sum\limits_{i=0}^{n-2}| nums[i+1]-[nums[i]|$So, if the input is like nums = [2, 4, 6], then the output will be 6, as when we reverse [4, 6] we will get the list as [2, 6, 4] and the value |2 − 6| + |6 − 4| = 6To solve this, we will follow these steps −if size of nums

Read More

Program to construct Maximum Stack with given operations in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 459 Views

Suppose we want to make a maximum stack, which supports following operations −MaxStk() this will construct a new instance of a maximum stackpush(val) inserts val to the stacktop() get the top most element from stackmax() get the maximum element from the stackpop() removes and returns the top most element from the stackpopmax() removes and returns the maximum element from the stackNow construct the maximum stack by calling MasStk(), then push three values like 5, 15, 10, then call top(), max(), popmax(), max() pop(), top() functions respectively. then the initial stack status will be [5, 15, 10], and corresponding output for ...

Read More

Check if given number is a power of d where d is a power of 2 in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 211 Views

Suppose we a number n and another value x, we have to check whether it is a power of x or not, where x is a number power of 2.So, if the input is like n = 32768 x = 32, then the output will be True as n is x^3.To solve this, we will follow these steps −From the main method do the following −cnt := 0if n is not 0 and (n AND (n - 1)) is same as 0, thenwhile n > 1, don = n/2cnt := cnt + 1return cnt mod (log c base 2) is ...

Read More

Program to find sum of rectangle whose sum at most k in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 364 Views

Suppose we have a 2d matrix and another value k, we have to find the largest sum of a rectangle where sum ≤ k.So, if the input is like5−2710and k = 15, then the output will be 12, as we can take the rectangle [5, 7] to get sum of 12 less than 15.To solve this, we will follow these steps −n := row count of am := column count of aans := inffor i1 in range 0 to n, dorow := a list of size m and fill with 0for i2 in range i1 to n, dofor j in ...

Read More
Showing 491–500 of 3,768 articles
« Prev 1 48 49 50 51 52 377 Next »
Advertisements