Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to find how many lines intersect in Python

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

Sometimes we need to find how many lines intersect within a given range. Given a list of lines in the form (m, c) representing y = mx + c, we can determine which lines intersect between x = l and x = h. So, if the input is like input_list = [[4, 6], [-6, 10], [8, 12]], l = 0, h = 2, then the output will be 2. ...

Read More

Program to find out the total number of characters to be changed to fix a misspelled word in Python

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

This problem involves finding the minimum number of character changes needed to correct misspelled city names in a tour route. Given a list of cities that a bus visits in order and a list of one-way roads connecting cities, we need to find valid paths and calculate the minimum corrections required. Problem Understanding The algorithm uses dynamic programming to find the optimal path through valid roads while minimizing character differences between the given city names and actual city names. Algorithm Steps The solution follows these key steps − Create a helper function to calculate ...

Read More

Program to find out if a linked list is present in a given binary tree in Python

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

Suppose we are given a binary tree that has a root node 'root' and a linked list that has a head node 'head'. We have to find out if that linked list exists in that binary tree. If a set of nodes in the tree have links with each other in order as a linked list, and if that order is similar to that of the provided linked list, then we return 'True' or otherwise, we return 'False'. So, if the input is like ? 6 ...

Read More

Python Pandas - Return TimeDeltaIndex as object ndarray of datetime.datetime objects

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 170 Views

To return TimeDeltaIndex as object ndarray of datetime.timedelta objects, use the TimeDeltaIndex.to_pytimedelta() method. This method converts Pandas timedelta objects to Python's native datetime.timedelta objects. Syntax TimedeltaIndex.to_pytimedelta() Creating a TimeDeltaIndex First, let's create a TimeDeltaIndex object with various timedelta formats − import pandas as pd # Create a TimeDeltaIndex object with different timedelta formats tdIndex = pd.TimedeltaIndex(data=['10 day 5h 2 min 3us 10ns', '+22:39:19.999999', ...

Read More

Python Pandas - Return a dataframe of the components of the TimedeltaIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 198 Views

The TimedeltaIndex.components property in Pandas returns a DataFrame containing the individual components (days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) of each timedelta in the index. Creating a TimedeltaIndex First, let's create a TimedeltaIndex with various time durations ? import pandas as pd # Create a TimedeltaIndex with different time formats tdIndex = pd.TimedeltaIndex(data=['10 day 5h 2 min 35s 3us 10ns', '+22:39:19.999999', ...

Read More

Python Pandas - Extract the Number of nanoseconds for each element from TimeDeltaIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 168 Views

To extract the number of nanoseconds for each element from a TimeDeltaIndex object, use the TimedeltaIndex.nanoseconds property. This property returns only the nanosecond component (0-999) from each timedelta, not the total nanoseconds. Syntax TimedeltaIndex.nanoseconds Creating a TimeDeltaIndex First, let's create a TimeDeltaIndex with various time components including nanoseconds ? import pandas as pd # Create a TimeDeltaIndex object with timedelta-like data tdIndex = pd.TimedeltaIndex(data=['10 day 5h 2 min 35s 3us 10ns', '+22:39:19.999999', ...

Read More

Python Pandas - Extract the Number of microseconds for each element from TimeDeltaIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 162 Views

To extract the number of microseconds for each element from TimeDeltaIndex object, use the TimedeltaIndex.microseconds property. This property returns an Int64Index containing the microsecond component of each timedelta. Creating a TimeDeltaIndex First, let's create a TimeDeltaIndex object with various timedelta formats ? import pandas as pd # Create a TimeDeltaIndex object with different timedelta formats tdIndex = pd.TimedeltaIndex(data=['10 day 5h 2 min 35s 3us 10ns', '+22:39:19.999999', ...

Read More

Python Pandas - Extract the Number of seconds for each element from TimeDeltaIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 228 Views

To extract the number of seconds for each element from TimeDeltaIndex object, use the TimedeltaIndex.seconds property. This property returns the seconds component (0-59) of each timedelta element. Creating a TimeDeltaIndex First, let's create a TimeDeltaIndex with various time intervals ? import pandas as pd # Create a TimeDeltaIndex object with different time intervals tdIndex = pd.TimedeltaIndex(data=['10 day 5h 2 min 35s 3us 10ns', '+22:39:19.999999', ...

Read More

Program to find length of longest repeating substring in a string in Python

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

A repeating substring is a substring that occurs at least twice in a string. In this tutorial, we'll find the length of the longest repeating substring using Python's suffix array approach. So, if the input is like s = "abdgoalputabdtypeabd", then the output will be 3, because the longest substring that occurs more than once is "abd". Algorithm Overview To solve this problem, we will follow these steps − Generate all suffixes of the string Sort the suffixes lexicographically Find the longest common prefix between adjacent suffixes Return the maximum length found Helper ...

Read More

Program to find length longest prefix sequence of a word array in Python

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

Suppose we have a list of words called w, with lowercase strings. We have to find the length of the longest sequence of w where each previous word is the prefix of the next word and the next word has just one new character appended. So, if the input is like w = ["pqr", "pq", "m", "mn", "pqrs"], then the output will be 3 because we can get the sequence: ["pq", "pqr", "pqrs"], whose length is 3. Algorithm To solve this, we will follow these steps − Sort the list w ...

Read More
Showing 2751–2760 of 61,297 articles
« Prev 1 274 275 276 277 278 6130 Next »
Advertisements