Server Side Programming Articles

Page 248 of 2109

Program to find how many updates required to make string half monotonous in Python

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

Suppose we have a lowercase string s whose length is even. We have to find the minimum number of characters that need to be updated such that one of the following three conditions is satisfied for all i, where 0 ≤ i < n/2 and j, n/2 ≤ j < n − s[i] > s[j] (left half characters greater than right half) s[i] < s[j] (left half characters less than right half) s[i] == s[j] (left half characters equal to right half) So, if the input is ...

Read More

Python Pandas - How to Round the DateTimeIndex with minute frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 1K+ Views

To round the DateTimeIndex with minute frequency, use the DateTimeIndex.round() method. For minute frequency, use the freq parameter with value 'T'. Creating a DateTimeIndex First, let's create a DateTimeIndex with seconds frequency to demonstrate the rounding operation ? import pandas as pd # DatetimeIndex with period 5 and frequency as 45 seconds # timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-09-29 07:00', periods=5, tz='Australia/Adelaide', freq='45s') # display DateTimeIndex print("DateTimeIndex...", datetimeindex) print("DateTimeIndex frequency...", datetimeindex.freq) The output of the above code is ? DateTimeIndex... DatetimeIndex(['2021-09-29 07:00:00+09:30', '2021-09-29 07:00:45+09:30', ...

Read More

Python Pandas - How to Round the DateTimeIndex with hourly frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 948 Views

To round the DateTimeIndex with hourly frequency, use the DateTimeIndex.round() method. For hourly frequency, use the freq parameter with value 'H'. Creating a DateTimeIndex At first, import the required libraries and create a DateTimeIndex with period 5 and frequency as 35 minutes − import pandas as pd # Create DatetimeIndex with period 5 and frequency as 35 minutes datetimeindex = pd.date_range('2021-09-29 07:00', periods=5, tz='Australia/Adelaide', freq='35T') # Display DateTimeIndex print("DateTimeIndex...", datetimeindex) DateTimeIndex... DatetimeIndex(['2021-09-29 07:00:00+09:30', '2021-09-29 07:35:00+09:30', '2021-09-29 ...

Read More

Program to find minimum costs needed to fill fruits in optimized way in Python

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

Suppose we have a list called fruits and two values k and cap. Each fruits[i] contains three values: [c, s, t], where fruit i costs c each, has size s, and there are t total fruits available. The k represents number of fruit baskets with capacity cap. We want to fill the fruit baskets with the following constraints in this order ? Each basket can only hold same type fruits Each basket should be as full as possible Each basket should be as cheap as possible ...

Read More

Python Pandas - Snap time stamps in DateTimeIndex to nearest occurring frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 260 Views

To snap time stamps in DateTimeIndex to nearest occurring frequency, use the DateTimeIndex.snap() method. This method rounds timestamps to the nearest frequency boundary, such as month-end, week-start, or any other valid frequency. Syntax DateTimeIndex.snap(freq) Parameters freq: A frequency string (e.g., 'M' for month-end, 'W' for week, 'D' for day) Basic Example Let's create a DateTimeIndex and snap timestamps to the nearest month-end ? import pandas as pd # Create DatetimeIndex with period 6 and frequency as D i.e. day # The timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-10-20 ...

Read More

Program to find minimum cost to send same number of people to two different cities in Python

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

Suppose we have a list called costs, where costs[i] has [c1, c2] indicating that for person i it costs c1 amount to reach city 0 and c2 amount to reach city 1. We want the same number of people to go to city 0 as city 1, and we need to find the minimum cost required. So, if the input is like costs = [[2, 6], [10, 3], [4, 9], [5, 8]], then the output will be 17, because person 0 and 2 will go to city 0 and person 1 and 3 to city 1. For city 0, ...

Read More

Program to check first player can win by reaching total sum to target in Python

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

Suppose we have two numbers k and target. Now consider Amal and Bimal are playing a game. In each round, Amal picks a number from 1 to k to add to the total score that initially starts from 0. Whoever crosses the total to target wins. Amal always plays first, we have to check whether he can force a win if both of them play optimally. So, if the input is like k = 5, target = 10, then the output will be True, as if Amal picks 4 first, then whether Bimal picks 1, 2, ..., or 5, ...

Read More

Program to find indices or local peaks in Python

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

A local peak is an element that is greater than or equal to its neighbors. In Python, we can find indices of local peaks by comparing each element with its adjacent elements. A peak can be a single element or a plateau (consecutive equal elements that are peaks). Peak Definition An index i is a peak when these conditions are met: The next different number is either absent or smaller than nums[i] The previous different number is either absent or smaller than nums[i] There is at least one different number on either side Algorithm ...

Read More

Python Pandas - Return an Index of formatted strings specified by date format

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 338 Views

The DateTimeIndex.strftime() method in Pandas returns an Index of formatted strings based on a specified date format. This method is useful for converting datetime objects into human-readable string representations. Syntax DateTimeIndex.strftime(date_format) Parameters: date_format − A string specifying the format using strftime directives Creating a DateTimeIndex First, let's create a DateTimeIndex with timezone information − import pandas as pd # Create DatetimeIndex with period 7 and frequency as 2 days datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=7, tz='Australia/Adelaide', freq='2D') print("DateTimeIndex...") print(datetimeindex) DateTimeIndex... DatetimeIndex(['2021-10-30 02:30:50+10:30', '2021-11-01 02:30:50+10:30', ...

Read More

Python Pandas - Convert times to midnight in DateTimeIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 1K+ Views

To convert times to midnight in DateTimeIndex, use the DateTimeIndex.normalize() method in Pandas. This method sets the time component of all datetime values to 00:00:00 while preserving the date and timezone information. What is normalize()? The normalize() method converts the time component of datetime values to midnight (00:00:00). This is useful when you want to work with dates only, ignoring the time portion. Creating a DateTimeIndex First, let's create a DateTimeIndex with various times ? import pandas as pd # Create DateTimeIndex with period 7 and frequency as 10H (10 hours) # The ...

Read More
Showing 2471–2480 of 21,090 articles
« Prev 1 246 247 248 249 250 2109 Next »
Advertisements