Programming Articles

Page 149 of 2547

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 539 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 269 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

Program to find out the minimum value from sum of node values of sub-trees in Python

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

Suppose we have a tree with nodes numbered 1 to n, where each node contains an integer value. When we remove any edge from the tree, it splits into two sub-trees. Our goal is to find the minimum possible difference between the sums of node values in these two sub-trees. The tree is given as a collection of edges, and the node values are provided in a list. Problem Understanding If the input is n = 6, edge_list = [[1, 2], [1, 3], [2, 4], [3, 5], [3, 6]], values = [15, 25, 15, 55, 15, 65], ...

Read More

Python Pandas CustomBusinessHour - Check if the given timestamp is on offset or not

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 321 Views

To check if a given timestamp is on offset or not, use the CustomBusinessHour.is_on_offset() method in Pandas. This method returns True if the timestamp falls within the custom business hours, and False otherwise. What is CustomBusinessHour? CustomBusinessHour is a DateOffset subclass that allows you to define custom business hours with specific start and end times. The is_on_offset() method checks whether a given timestamp falls within these defined business hours. Syntax CustomBusinessHour.is_on_offset(timestamp) Example Let's create a CustomBusinessHour offset and check if different timestamps are within the business hours ? import pandas ...

Read More

Python Pandas - Check if the given CustomBusinessHour is Anchored

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 148 Views

To check if a given CustomBusinessHour is anchored, use the is_anchored() method in Pandas. An anchored offset is tied to a specific point in time, like the beginning of a month or day. What is CustomBusinessHour? CustomBusinessHour is a DateOffset subclass that allows you to define custom business hours with specific start and end times ? import pandas as pd # Create a CustomBusinessHour offset with business hours 9:30 AM to 6:30 PM cbh_offset = pd.tseries.offsets.CustomBusinessHour(start="09:30", end="18:30") print("CustomBusinessHour Offset:", cbh_offset) CustomBusinessHour Offset: Checking if CustomBusinessHour is Anchored The ...

Read More
Showing 1481–1490 of 25,469 articles
« Prev 1 147 148 149 150 151 2547 Next »
Advertisements