Python Articles

Page 266 of 855

Program to find maximum score of brick removal game in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 304 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 281 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 246 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 369 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 235 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 325 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 153 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

Python Pandas CustomBusinessHour - Roll provided date forward to next offset only if not on offset

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 266 Views

The rollforward() method in Pandas CustomBusinessHour moves a date forward to the next valid business hour only if the date is not already on a valid offset. If the date is already aligned with the custom business hour schedule, it remains unchanged. Understanding CustomBusinessHour CustomBusinessHour allows you to define custom business days and hours. It's useful when your business operates on non-standard schedules ? import pandas as pd # Create a CustomBusinessHour offset # n=5 means 5 business hours, weekmask defines valid days cbh_offset = pd.tseries.offsets.CustomBusinessHour(n=5, weekmask='Mon Tue Wed Fri') print("CustomBusinessHour Offset:") print(cbh_offset) ...

Read More

Python Pandas - Create a CustomBusinessHour Offset object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 210 Views

To create a CustomBusinessHour object, use the pandas.tseries.offsets.CustomBusinessHour() method in Pandas. This offset allows you to define custom business hours with specific weekdays and time ranges. Syntax pandas.tseries.offsets.CustomBusinessHour(n=1, normalize=False, start='09:00', end='17:00', weekmask='Mon Tue Wed Thu Fri', calendar=None, offset=timedelta(0)) Parameters n − Number of business hours to offset (default: 1) weekmask − Valid business days as a string (default: 'Mon Tue Wed Thu Fri') start − Start time of business hours (default: '09:00') end − End time of business hours (default: '17:00') Basic Example Let's create a CustomBusinessHour offset with custom ...

Read More

Python Pandas - Get the weekmask applied on the CustomBusinessDay offset

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 270 Views

The weekmask property in Pandas allows you to retrieve the custom business days pattern applied to a CustomBusinessDay offset. This is useful for understanding which days of the week are considered valid business days in your custom offset. What is CustomBusinessDay? CustomBusinessDay is a DateOffset subclass that represents custom business days while excluding holidays. Unlike standard business days (Mon-Fri), you can specify your own pattern of valid business days using a weekmask. Creating a CustomBusinessDay with Weekmask First, let's create a timestamp and a CustomBusinessDay offset with a custom weekmask − import pandas as ...

Read More
Showing 2651–2660 of 8,546 articles
« Prev 1 264 265 266 267 268 855 Next »
Advertisements