Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 120 of 377

Program to find sum of the sum of all contiguous sublists in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 484 Views

Given a list of numbers, we need to find the sum of all possible contiguous subarrays and return the result modulo 109 + 7. This problem can be solved efficiently by calculating how many times each element appears in all subarrays. For the input nums = [3, 4, 6], we have these contiguous subarrays: [3], [4], [6], [3, 4], [4, 6], [3, 4, 6]. Their sums are 3, 4, 6, 7, 10, 13 respectively, totaling 43. Understanding the Pattern Instead of generating all subarrays, we can calculate how many times each element contributes to the final sum. ...

Read More

Program to check we can reach end of list by starting from k in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 415 Views

Suppose we have a list of numbers called nums and another number k. If we start at index k and at any index i, we can go either left or right by exactly nums[i] number of steps. We have to check whether we can reach the end of the list or not. So, if the input is like nums = [0, 0, 2, 1, 3, 3, 1, 1] and k = 2, then the output will be True, as if we start at index 2, then jump to index 4 and then jump to the last index 7. ...

Read More

Program to find how many ways we can climb stairs (maximum steps at most k times) in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 296 Views

Suppose we have a staircase with n steps and we also have another number k. Initially we are at stair 0, and we can climb up either 1, 2 or 3 steps at a time, but we can only climb 3 stairs at most k times. We need to find the number of ways we can climb the staircase. So, if the input is like n = 5, k = 2, then the output will be 13, as there are different ways we can climb the stairs − [1, 1, 1, 1, 1] [2, 1, 1, 1] ...

Read More

Program to find how many ways we can climb stairs in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 395 Views

Suppose we have a staircase with n steps, and we can climb up either 1 or 2 steps at a time. We need to find the number of unique ways we can climb the staircase. The order of the steps matters, so each different sequence counts as a unique way. If the answer is very large, we return the result modulo 10^9 + 7. For example, if n = 5, there are 8 unique ways ? 1, 1, 1, 1, 1 2, 1, 1, 1 1, 2, 1, 1 1, 1, 2, 1 1, 1, 1, ...

Read More

Program to find minimum number of busses are required to pass through all stops in Python

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

Suppose we have a list of numbers called nums representing bus stops on a line where nums[i] shows the time a bus must arrive at station i. Since buses can only move forward in time, we need to find the minimum number of buses required to pass through all stops. So, if the input is like nums = [1, 2, 7, 9, 3, 4], then the output will be 2, as one bus can take stops [1, 2, 3, 4] and another can handle [7, 9]. Algorithm To solve this, we will follow these steps ? ...

Read More

Program to find maximum amount we can get by taking different items within the capacity in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 638 Views

The 0/1 Knapsack problem is a classic optimization problem where we have items with weights and values, and we need to find the maximum value we can obtain within a given weight capacity. Each item can be taken at most once. Given two lists weights and values of the same length and a capacity k, where weights[i] and values[i] represent the weight and value of the i-th item, we need to find the maximum value achievable without exceeding the capacity limit. Problem Example If we have weights = [2, 3, 4], values = [2, 6, 4], and ...

Read More

Program to find the sum of elements that forms a Z shape on matrix in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 499 Views

Suppose we have one n x n matrix M, we have to find the sum of all elements that form a Z shape in the matrix. A Z-shape consists of three parts: the first row (top horizontal line), the diagonal from top-right to bottom-left (middle diagonal), and the last row (bottom horizontal line). Example Matrix So, if the input is like ? 4 3 2 9 1 8 2 5 6 Then the output will be 23, as elements are [4+3+2+1+2+5+6] = 23. Algorithm To solve this, we will follow these steps ? n := row count of matrix if n

Read More

Program to check we can spell out the target by a list of words or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 248 Views

Given a list of numbers and a starting index, we need to determine if we can reach the end of the list by jumping. At any index i, we can move left or right by exactly nums[i] steps. For example, with nums = [0, 0, 2, 1, 3, 3, 1, 1] and starting index k = 2, we can reach the end by jumping from index 2 to index 4, then to the last index 7. Algorithm We'll use a breadth-first search (BFS) approach to explore all possible positions: Initialize a visited array to track ...

Read More

Program to find the maximum profit we can get by buying on stock market multiple times in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 353 Views

Suppose we have a list of prices representing the stock prices of a company in chronological sequence, we have to find the maximum profit we could have made from buying and selling that stock any number of times. We have to keep in mind that we must buy before we can sell it. So, if the input is like prices = [10, 50, 30, 40, 60], then the output will be 70, as we can buy at 10, sell at 50, buy at 30, and sell at 60. Algorithm To solve this, we will follow these steps: ...

Read More

Program to check whether given graph is bipartite or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 897 Views

A bipartite graph is an undirected graph where vertices can be divided into two disjoint sets such that no two vertices within the same set are adjacent. In other words, every edge connects vertices from different sets. For example, if we have the following graph: 0 1 2 3 4 ...

Read More
Showing 1191–1200 of 3,768 articles
« Prev 1 118 119 120 121 122 377 Next »
Advertisements