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
Programming Articles
Page 124 of 2547
Program to check whether there is any pair of words which are almost same in Python
Suppose we have a list of lowercase strings called words where each word is of same length. We have to check whether there are two strings that differ only in one character. So, if the input is like words = ["seed", "pick", "lick", "root", "live"], then the output will be True, as "pick" and "lick" are almost same. Algorithm To solve this, we will follow these steps − Create a new set to store patterns For each word in words, do ...
Read MoreProgram to find probability of getting assigned seat for the last person in an airplane after seat shuffling in Python
Suppose we have an integer n, representing the number of seats in an airplane. The first passenger has lost his ticket, so he picks a random seat. Everyone else has their ticket, but if their seat is already taken, they will also select an available seat randomly. We need to find the probability that the last person gets their assigned seat. So, if the input is like n = 5, then the output will be 0.5. The answer is always constant when there is more than one person - either they get the correct seat or not, so probability ...
Read MoreProgram 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 More