Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 34 of 377

Program to find maximum score of a good subarray in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 550 Views

Suppose we have an array called nums and a value k. The score of a subarray (i, j) is defined as the minimum value in subarray nums[i..j] multiplied by its length (j-i+1). A good subarray is one where i = minNum while i > -1 and nums[i] >= minNum: i -= 1 # Expand right while elements are >= minNum ...

Read More

Program to make the XOR of all segments equal to zero in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 397 Views

Suppose we have an array called nums and another value k. The XOR of a segment [left, right] (left 0: for j, prev in enumerate(dp): new_dp[i ^ j] = max(new_dp[i ^ j], prev + cnt) dp = new_dp ...

Read More

Program to find max chunks to make array sorted in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 304 Views

Suppose we have an array nums, we have to split the array into some number of partitions, and individually sort each of them. After concatenating them we will get one sorted array. We have to find the maximum number of partitions we could have made? So, if the input is like [3, 2, 4, 5, 5], then the output will be 4, as we can make partitions like [3, 2], [4], [5], [5]. Algorithm To solve this, we will follow these steps − real := sort the list nums p1 := 0, p2 := 1, ...

Read More

Program to find out if a vertex in an undirected graph has a lesser cost path in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 225 Views

Suppose, we are given a weighted, undirected graph. We have to implement a function query that takes two vertices and a cost 'limit' as input and checks if there exists a path with cost less than or equal to the given limit. We return true if such a path exists, otherwise we return false. So, if the input is like ? and the queries are (0, 2, 10), (3, 1, 30), (4, 3, 30). then the output will be ? False True True The result of the first query is False ...

Read More

Program to find maximize palindrome length from subsequences in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 227 Views

Given two strings s and t, we need to find the maximum length palindrome that can be formed by concatenating a subsequence from s with a subsequence from t. A subsequence preserves the relative order of characters but doesn't need to be contiguous. Problem Approach The key insight is to use dynamic programming to find the longest palindromic subsequence in the combined string, then check all possible ways to form palindromes using characters from both strings ? Concatenate both strings to form a combined string Use DP to find longest palindromic subsequence for any substring Check ...

Read More

Program to check whether one point can be converted to another or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 197 Views

Suppose we have a starting point (sx, sy) and a target point (tx, ty). We need to check whether a sequence of moves exists to transform the start point to the end point. Each move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y). This problem can be solved using a recursive approach by working backwards from the target point to check if we can reach the starting point. Algorithm Steps To solve this problem, we follow these steps ? If sx > tx or sy > ...

Read More

Program to find out the sum of evenly spaced elements in an array in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 407 Views

Suppose, there is an array nums of size n containing positive integers. We have another array queries that contain integer pairs (pi, qi). For every query in the array queries, the answer will be the sum of numbers in the array nums[j] where pi ≤ j < n and (j - pi) is divisible by qi. We have to return the answer of all such queries, and if it is a large value, we return the answer modulo 10^9 + 7. So, if the input is like nums = [2, 3, 4, 5, 6, 7, 8, 9, 10], queries ...

Read More

Program to count the number of ways to distribute n number of candies in k number of bags in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 613 Views

Suppose we have n candies and k bags, and we need to distribute the candies such that each bag contains at least one candy. Since every candy is unique, we must count all possible ways to distribute them among the bags. This is a classic problem that can be solved using Stirling numbers of the second kind, which count the number of ways to partition n distinct objects into k non-empty subsets, multiplied by k! to account for the distinct bags. Problem Understanding For n = 3 candies and k = 2 bags, the possible distributions are ...

Read More

Program to find maximum subarray min-product in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 370 Views

Suppose we have an array nums, we need to find the maximum min-product of each non-empty subarray. The min-product of an array is equal to the minimum value in the array multiplied by the sum of the array. Since the answer can be large, we return it modulo 10^9+7. For example, if we have an array [4, 3, 6], the minimum value is 3 and the sum is 13, so the min-product is 3 × 13 = 39. Problem Example If the input is nums = [2, 3, 4, 3], the output will be 30. We can ...

Read More

Program to find maximum distance between a pair of values in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 745 Views

Given two arrays nums1 and nums2, we need to find the maximum distance between valid index pairs (i, j). A pair is valid if i

Read More
Showing 331–340 of 3,768 articles
« Prev 1 32 33 34 35 36 377 Next »
Advertisements