Programming Articles

Page 262 of 2547

Program to find buildings from where sea can be visible in Python

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

Suppose we have a list of heights of different buildings. A building with height value heights[i] can see the ocean when every building on its right are shorter than that building. We have to find the building indices from where we can see the ocean, in ascending order. So, if the input is like heights = [8, 12, 12, 9, 10, 6], then the output will be [2, 4, 5] because we can see the ocean from building height 12 at index 2, from building height 10 at index 4 and from last building at index 5. Algorithm ...

Read More

Program to find number of unique people from list of contact mail ids in Python

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

Suppose we have a list of contact entries, where each entry contains multiple email addresses belonging to the same person. We need to find the number of unique people by identifying contacts that share common email addresses. A contact is considered duplicate when it shares any email with a previously processed contact. So, if the input is like contacts = [["alex@gmail.com", "alex@yahoo.com"], ["alex_25@yahoo.com", "alex@gmail.com"], ["bob15@gmail.com"]], then the output will be 2. The first and second contacts share "alex@gmail.com", so they represent the same person, leaving us with two unique people. Algorithm To solve this, we will follow ...

Read More

Python Pandas - Get the maximum value from Ordered CategoricalIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 466 Views

To get the maximum value from an Ordered CategoricalIndex, use the catIndex.max() method in Pandas. The maximum value is determined by the order of categories, not alphabetical sorting. Creating an Ordered CategoricalIndex First, import the required libraries and create a CategoricalIndex with ordered categories ? import pandas as pd # Create an ordered CategoricalIndex catIndex = pd.CategoricalIndex( ["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"] ) print("Categorical Index...") print(catIndex) Categorical Index... CategoricalIndex(['p', ...

Read More

Program to check words can be found in matrix character board or not in Python

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

Suppose we have a matrix character board where each cell holds a character. We also have a string called target, and we need to check whether the target can be found in the matrix by going left-to-right (horizontally) or top-to-bottom (vertically) in a unidirectional way. Problem Example If the input matrix is ? a n t s s p i n l a p s And word = "tip", then the output will be True because the third column (top to bottom) forms "tip". Algorithm To ...

Read More

Python Pandas - Get the minimum value from Ordered CategoricalIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 189 Views

To get the minimum value from an Ordered CategoricalIndex, use the catIndex.min() method in Pandas. This method returns the first category in the ordered sequence, not the alphabetically smallest value. Creating an Ordered CategoricalIndex First, let's create a CategoricalIndex with ordered categories ? import pandas as pd # Create an ordered CategoricalIndex catIndex = pd.CategoricalIndex( ["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"] ) print("Categorical Index...") print(catIndex) Categorical Index... CategoricalIndex(['p', 'q', 'r', ...

Read More

Python Pandas - Create an Index based on an underlying Categorical

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 585 Views

To create an Index based on an underlying Categorical, use the pandas.CategoricalIndex() method. A CategoricalIndex can only take on a limited and usually fixed number of possible values, making it memory-efficient for repetitive data. Syntax pandas.CategoricalIndex(data=None, categories=None, ordered=None, dtype=None) Parameters The key parameters for creating a CategoricalIndex are ? data − Array-like values for the categorical index categories − List of possible values (categories) ordered − Boolean indicating if categories have a meaningful order dtype − Data type, typically 'category' Creating a Basic CategoricalIndex First, import pandas and create ...

Read More

Python Pandas - Display the value of the step parameter of RangeIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 346 Views

To display the value of the step parameter of RangeIndex, use the index.step property in Pandas. RangeIndex is a memory-efficient special case of Int64Index that represents monotonic ranges without storing all values in memory. What is RangeIndex? RangeIndex is optimized for representing evenly spaced integer sequences. It stores only the start, stop, and step values rather than all individual index values, making it memory-efficient for large ranges. Creating a RangeIndex First, let's create a RangeIndex with specific parameters ? import pandas as pd # Create a RangeIndex with start=10, stop=30, step=2 index = ...

Read More

Program to find minimum time required to complete tasks with k time gap between same type tasks in Python

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

Suppose we have a list of integers called tasks where each item represents a different task type, and a non-negative integer k. Each task takes one unit of time to complete and tasks must be completed in the given order, but we must have k units of time between executing two tasks of the same type. At any time, we can either execute a task or wait. We need to find the minimum time required to complete all tasks. For example, if tasks = [0, 1, 1, 2] and k = 2, the output will be 6. The first ...

Read More

Python Pandas - Display the value of the stop parameter of RangeIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 508 Views

To display the value of the stop parameter of RangeIndex, use the index.stop property in Pandas. RangeIndex is a memory-saving special case of Int64Index limited to representing monotonic ranges, which can improve computing speed in some instances. What is RangeIndex? RangeIndex represents a sequence of integers with a start, stop, and step value. It's similar to Python's range() function but optimized for pandas operations ? import pandas as pd # Create a RangeIndex with start=10, stop=30, step=2 index = pd.RangeIndex(start=10, stop=30, step=2, name="data") print("RangeIndex...") print(index) RangeIndex... RangeIndex(start=10, stop=30, step=2, name='data') ...

Read More

Python Pandas - Display the value of the start parameter of RangeIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 261 Views

To display the value of the start parameter of RangeIndex, use the index.start property in Pandas. RangeIndex is a memory-saving special case of Int64Index limited to representing monotonic ranges that can improve computing performance. What is RangeIndex? RangeIndex represents a monotonic integer range similar to Python's range() function. It stores only the start, stop, and step values instead of the entire sequence, making it memory-efficient for large ranges. Creating a RangeIndex You can create a RangeIndex by specifying start, stop, step, and an optional name ? import pandas as pd # Create a ...

Read More
Showing 2611–2620 of 25,466 articles
« Prev 1 260 261 262 263 264 2547 Next »
Advertisements