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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Program to check final answer by performing given stack operations in Python
Suppose we have a list of strings called ops where each element represents one of these stack operations ? A non-negative integer value that will be pushed onto the stack "POP" to delete the topmost element from the stack "DUP" to duplicate the top element and push it onto the stack "+" to pop the top two elements and push their sum "-" to pop the top two elements and push the result of (top element − second element) We need to find the topmost element in the stack after applying all operations. If any operation ...
Read MoreProgram to count how many swimmers will win the final match in Python
Suppose we have a list of numbers called nums whose length is n. The elements present in this list represent the current scores of swimmers in a competition. For the final match, the first place winner for this current round will get n points, the second place winner will get n-1 points and so on. We have to check the number of swimmers that can still win the competition in the final round after the current round. If there is a tie for the first place in points, that will also be counted as winning. So, if the input ...
Read MoreProgram 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 More