Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 5 of 377

Program to find winner of number reducing game in Python

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

Suppose Amal and Bimal are playing a number reducing game. They have a number n and follow these rules: If n is a power of 2, divide it by 2. Otherwise, reduce it by the next lower number which is also a power of 2. Whoever reduces the number to 1 wins the game. Amal always starts first. For example, if n = 19: Amal reduces 19 to 16 (19 - 16 = 16, where 16 is the largest power of 2 less than 19), then Bimal divides 16 by 2 to get 8, Amal divides 8 by 2 ...

Read More

Program to find number of magic sets from a permutation of first n natural numbers in Python

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

Suppose we have an array A with first n natural numbers, and one permutation P{p1, p2, ... pn} of array A. We have to check how many magic sets are there. A permutation is said to be magic set, if this satisfies these few rules − If we have k, then the elements in positions a[1], a[2], ... a[k] are less than their adjacent elements [P[a[i] - 1] > P[a[i]] < P[a[i] + 1]] If we have l, then the elements in positions b[1], b[2], ... b[l] are greater than their adjacent ...

Read More

Program to find number of sequences after adjacent k swaps and at most k swaps in Python

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

We need to find how many sequences can be generated from an array of first n natural numbers using exactly k adjacent swaps (S1) and at most k adjacent swaps (S2). Adjacent swaps means swapping elements at positions i and i+1. Problem Understanding Given an array A with first n natural numbers [1, 2, 3, ..., n], we calculate ? S1: Number of sequences after exactly k adjacent swaps S2: Number of sequences after at most k adjacent swaps Example Walkthrough For n = 3, k = 2 with original array [1, 2, ...

Read More

Program to find number of strictly increasing colorful candle sequences are there in Python

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

This problem asks us to find the number of strictly increasing colorful candle sequences. A sequence is strictly increasing based on candle heights, and colorful if it contains at least one candle of each color from 1 to k. The solution uses the inclusion-exclusion principle combined with a Binary Indexed Tree (BIT) to efficiently count valid subsequences. For each subset of colors, we count increasing subsequences, then apply inclusion-exclusion to ensure all k colors are present. Algorithm Explanation The approach works as follows − Use bit manipulation to represent subsets of colors (2^k possibilities) For ...

Read More

Program to find number of starting point from where we can start travelling in Python

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

Suppose there are n cities numbered from 0 to n-1 and there are n directed roads. We can travel from city i to city (i + 1) % n [0 to 1 to 2 to .... to N - 1 to 0]. We have a car with a fuel tank capacity of cap units. There are fuel[i] units of fuel available at city i and the car takes cost[i] units of fuel to travel from city i to (i + 1) % n. We need to find how many cities we can start from to travel around all cities and ...

Read More

Program to check robbers can rob the vault or not in Python

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

Suppose there are N robbers trying to rob a vault. A guard is away for G amount of time, and each robber needs a specific time to complete the robbery. At most two robbers can enter the vault simultaneously. We need to determine if all robbers can complete their task before the guard returns. Key Constraints If one robber enters the vault at time t and another exits at the same time t, they are never simultaneously inside. If the guard returns at time G and a robber exits exactly at time G, the guard won't notice. ...

Read More

Program to find maximum score of brick removal game in Python

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

Suppose Amal and Bimal are playing a game with an array nums representing n bricks with numbers on top. In this game, players can alternatively remove one, two, or three bricks from the top, and the numbers on the removed bricks are added to that player's score. If Amal always starts first, we need to find the maximum score Amal can secure. So, if the input is like nums = [1, 2, 3, 4, 5], then the output will be 6. Here's why: Amal can remove brick {1}, {1, 2} or {1, 2, 3}. If Amal selects the first ...

Read More

Program to find winner of array removal game in Python

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

Suppose Amal and Bimal are playing a game where they have one array A with some numbers. The game rules are as follows: Bimal will start always In each turn one player deletes the maximum element from the array and all other elements present at right of the deleted element will also be deleted They play alternatively The player who removes all remaining elements wins the game So, if the input is like nums = [5, 2, 6, 3, 4], then the output will be Amal because at first Bimal will remove [6, 3, 4] so ...

Read More

Program to count number of possible humble matrices in Python

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

Suppose we have two values n and m. We have to find the number of possible arrangements of humble matrices of order n × m. A matrix is said to be humble when: It contains each element in range 1 to n × m exactly once For any two indices pairs (i1, j1) and (i2, j2), if (i1 + j1) < (i2 + j2), then Mat[i1, j1] < Mat[i2, j2] should hold If the answer is too large, return the result modulo 109 + 7. Understanding Humble Matrices A humble matrix has elements arranged ...

Read More

Program to find out the minimal cost so that the citizens have access to a market in Python

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

Suppose, there are n cities and m roads connecting the cities. The citizens need markets where they can buy their commodities. Currently, there are no markets in the cities, and the roads between the cities are under construction. A two-way road can be built between two cities if: (i) The city contains a market; (ii) The cities can be visited by the road where there is a market. The cost of building a road is x, and building a market is y. We need to find the minimal cost to provide access to markets for citizens of each city. ...

Read More
Showing 41–50 of 3,768 articles
« Prev 1 3 4 5 6 7 377 Next »
Advertisements