Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to count number of overlapping islands in two maps in Python

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

Suppose we have two binary matrices mat1 and mat2. Here 1 represents land and 0 represents water. If there is a group of 1s (land) surrounded by water, it's called an island. We need to find the number of islands that exist in both mat1 and mat2 at the exact same coordinates. Problem Understanding Given two matrices, we need to count overlapping islands where both matrices have land (1) at the same positions. For example, if mat1 = 101 100 100 And mat2 = 101 100 101 ...

Read More

Program to find index, where we can insert element to keep list sorted in Python

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

Finding the correct insertion index to maintain sorted order is a common problem that can be efficiently solved using binary search. We need to find the rightmost position where we can insert the target element while keeping the list sorted in ascending order. Given a sorted list nums and a target value, we want to find the index where the target should be inserted. If the target already exists, we return the largest possible index (after all existing occurrences). Problem Example For nums = [1, 5, 6, 6, 8, 9] and target = 6, the output should ...

Read More

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 261 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 232 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 292 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 302 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
Showing 2821–2830 of 61,297 articles
« Prev 1 281 282 283 284 285 6130 Next »
Advertisements