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

Arnab Chakraborty
Updated on 26-Mar-2026 17:43:19

235 Views

A Binary Search Tree (BST) is a special type of binary tree where the left subtree contains values less than or equal to the root, and the right subtree contains values greater than or equal to the root. This problem asks us to find the largest BST subtree within a given binary tree. Original Tree: 1 4 6 ... Read More

Program to find out the k-th largest product of elements of two arrays in Python

Arnab Chakraborty
Updated on 26-Mar-2026 17:42:47

311 Views

Given two lists containing integer numbers, we need to find the k-th largest product by multiplying each element from the first list with each element from the second list. This problem can be efficiently solved using a min-heap to track the k largest products. So, if the input is like p = [2, 5], q = [6, 8], k = 2, then the output will be 16. The multiplication results are: 2 × 6 = 12, 2 × 8 = 16, 5 × 6 = 30, 5 × 8 = 40. When sorted in descending order: [40, 30, ... Read More

Program to find how many lines intersect in Python

Arnab Chakraborty
Updated on 26-Mar-2026 17:42:21

627 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
Updated on 26-Mar-2026 17:41:52

237 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
Updated on 26-Mar-2026 17:41:30

292 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
Updated on 26-Mar-2026 17:41:00

178 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
Updated on 26-Mar-2026 17:40:37

209 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
Updated on 26-Mar-2026 17:40:17

179 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
Updated on 26-Mar-2026 17:39:58

170 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
Updated on 26-Mar-2026 17:39:38

235 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

Advertisements