Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 10 of 377

Program to find the highest altitude of a point in Python

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

Suppose there is a biker who is going on a road trip. There are n different points in his road trip at different altitudes. The biker starts his trip from point 0 with altitude 0. If we have a sequence called gain with n elements, gain[i] is the net gain in altitude between points i and i + 1 for all (0

Read More

Program to find range sum of sorted subarray sums using Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 444 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 index right (1-indexed), inclusive, in the new array. The answer may be very large so return result modulo 10^9 + 7.So, if the input is like nums = [1, 5, 2, 6] left = 1 right = 5, then the output will be 20 because here all subarray sums are ...

Read More

Program to find latest valid time by replacing hidden digits in Python

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

Suppose we have a string s represents time in the form of hh:mm. Some of the digits in s are hidden (represented by ?). Considering 24hr clock, the valid times are between 00:00 and 23:59. We have to find the latest valid time that we can get from time by replacing the hidden digits.So, if the input is like s= "1?:?5", then the output will be 13:55 as the latest hour beginning with the digit '2' is 23 and the latest minute ending with the digit '0' is 50.To solve this, we will follow these steps −ans := a new ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 686 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,7,2,12,16], then the output will be 1 because we can make given array to [1,1,0,1,1], so the maximum is 1 and minimum is 0, so the difference is 1.To solve this, we will follow these steps −if size of nums

Read More

Program to find maximum number of balls in a box using Python

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

Suppose we have a ball factory where we have n balls numbered from l to r (both inclusive) and have an infinite number of boxes numbered from 1 to infinity. So if we put each ball in the box with a number same to the sum of digits of the ball's number. (As an example, the ball number 123 will be put in the box number 1 + 2 + 3 = 6). So if we have two values l and r, we have to find the number of balls in the box with the most balls.So, if the input ...

Read More

Program to find sum of unique elements in Python

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

Suppose we have an array nums with few duplicate elements and some unique elements. We have to find the sum of all the unique elements present in nums.So, if the input is like nums = [5, 2, 1, 5, 3, 1, 3, 8], then the output will be 10 because only unique elements are 8 and 2, so their sum is 10.To solve this, we will follow these steps −count := a dictionary holding all unique elements and their frequencyans := 0for each index i and value v in nums, doif count[v] is same as 1, thenans := ans + ...

Read More

Program to find path with maximum probability using Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 574 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 find the path with the maximum probability of success to go from start to end and return its success probability. If we cannot find any path, then return 0.So, if the input is likethen the output will be 0.24 because there are two paths from node 0 to 2, one ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 473 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 where each edge e has [u, v] represents u is parent and v is child. We have to find an array A of size n, represents number of nodes in the subtree of the ith node with same label as iSo, if the input is likeHere n = 5 and ...

Read More

Program to find minimum changes required for alternating binary string in Python

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

Suppose we have a binary string s. Let us consider an operation where we can flip one bit. The string s is called alternating string if no two adjacent characters are same. We have to find the minimum number of operations needed to make s alternating.So, if the input is like s = "11100011", then the output will be 3 because if we flip bits at position 1, 4 and 7, then, it will be "10101010", then all are alternating.To solve this, we will follow these steps −change := 0even_1 := 0, even_0 := 0odd_1 := 0, odd_0 := 0for ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 402 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 to find the number of good splits we can make in s.So, if the input is like s = "xxzxyx", then the output will be 2 as there are multiple ways of splitting but if we split like ("xxz", "xyx") or ("xxzx", "yx") then they are good.To solve this, we ...

Read More
Showing 91–100 of 3,768 articles
« Prev 1 8 9 10 11 12 377 Next »
Advertisements