Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 258 of 2109
Program to check heap is forming max heap or not in Python
Suppose we have a list representing a heap tree. As we know, a heap is a complete binary tree. We have to check whether the elements are forming a max heap or not. In a max heap, every parent element is larger than both of its children. So, if the input is like nums = [8, 6, 4, 2, 0, 3], then the output will be True because all parent elements are larger than their children. 8 ...
Read MoreProgram to check all listed delivery operations are valid or not in Python
Suppose we have a list of strings called orders. Each element in the orders list starts with either "P" or "D". The "P" indicates that an order is picked up, and "D" means delivery. These letters are followed by the order id number. For example, "P6" indicates pick up order 6. We have to check whether the orders list is valid or not based on these rules ? We cannot deliver an order before pickup Every pickup must be delivered An order which has already been picked up and delivered cannot be picked up or delivered again ...
Read MoreProgram to find buildings from where sea can be visible in Python
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 MoreProgram to find number of unique people from list of contact mail ids in Python
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 MorePython Pandas - Get the maximum value from Ordered CategoricalIndex
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 MoreProgram to check words can be found in matrix character board or not in Python
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 MorePython Pandas - Get the minimum value from Ordered CategoricalIndex
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 MorePython Pandas - Create an Index based on an underlying Categorical
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 MorePython Pandas - Display the value of the step parameter of RangeIndex
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 MoreProgram to find minimum time required to complete tasks with k time gap between same type tasks in Python
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