Found 26504 Articles for Server Side Programming

Program to check how many queries finds valid arithmetic sequence in Python

Arnab Chakraborty
Updated on 16-Oct-2021 09:55:51

262 Views

Suppose we have a list of numbers called nums and also have list of queries. Where each query element contains [i, j]. So this query is asking whether the sublist of nums from [i, j] (both inclusive), is an arithmetic sequence or not. So finally we have to find the count of queries that return true.So, if the input is like nums = [2, 4, 6, 8, 7, 6, 5, 2] queries = [[3, 4], [0, 3], [2, 4]], then the output will be 2, because [2, 4, 6, 8] is an arithmetic sequence, so query [0, 3] is true. ... Read More

Program to find maximum number of people we can make happy in Python

Arnab Chakraborty
Updated on 14-Oct-2021 12:50:52

566 Views

Suppose we have a list customers and another list mood, these two are of same length, we also have another integer k. Now on each minute i, customers[i] number of people come to the store and when mood[i] = 1, it indicates the customers are happy and when mood[i] = 0, then they are sad. We can set a sublist of size k of mood to 1s, finally we have to find the maximum number of people we can make happy.So, if the input is like customers = [2, 3, 6, 6, 3] mood = [1, 1, 0, 0, 0] ... Read More

Program to check string is palindrome or not with equivalent pairs in Python

Arnab Chakraborty
Updated on 14-Oct-2021 12:45:51

185 Views

Suppose we have a lowercase alphabet string called s and also have a list of pairs called 'pairs'. Each element in pairs has two strings [a, b] where the character 'a' and 'b' are considered same. If there are two pairs like [a, b] and [b, c], then we can say a and b are equivalent also b and c are equivalent, so a and c are also equivalent. And any value a or b is equivalent to itself. We have to check whether s is a palindrome or not with the given equivalence relations.So, if the input is like ... Read More

Program to check whether there is any pair of words which are almost same in Python

Arnab Chakraborty
Updated on 14-Oct-2021 12:38:43

479 Views

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.To solve this, we will follow these steps −s := a new setfor each word in words, dofor each index i and word w in word, doif substring of word[from index 0 to i - 1] concatenate "*" concatenate word[from index i + 1 ... Read More

Program to find probability of getting assigned seat for the last person in an airplane after seat shuffling in Python

Arnab Chakraborty
Updated on 14-Oct-2021 12:34:31

215 Views

Suppose we have an integer n, that is representing the number of seats in an airplane. Now consider the first passenger has lost his ticket, so he picks a random seat. Now everyone else has their ticket but if their seat is already taken, they will also select an available seat randomly. We have 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, because either they have got the correct seat ... Read More

Program to check final answer by performing given stack operations in Python

Arnab Chakraborty
Updated on 14-Oct-2021 12:31:53

816 Views

Suppose we have a list of string called ops where each element is any one of these operations like below −A non-negative integer value that will be pushed into a stack"POP" to delete top most element from the stack"DUP" to insert top element again into the stack, to make it duplicate"+" to pop out the top two elements and push the sum value"-" to pop out the top two elements and push the result of (top element - element just below top)So we have to find the top mot element in the stack after applying all of these operations. If ... Read More

Program to count how many swimmers will win the final match in Python

Arnab Chakraborty
Updated on 14-Oct-2021 12:01:04

372 Views

Suppose we have a list of numbers called nums whose length is n. The elements present in this list are representing the current score of swimmers in a competition. For the final match the first place winner for this current round will get n scores, 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 in points, that will also be counted as winning.So, if the input is like ... Read More

Program to check heap is forming max heap or not in Python

Arnab Chakraborty
Updated on 14-Oct-2021 11:54:51

1K+ Views

Suppose we have a list representing a heap tree. As we know heap is a complete binary tree. We have to check whether the elements are forming max heap or not. As we know for max heap every 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 elements are larger than their children.To solve this, we will follow these steps −n := size of numsfor i in range 0 to n - 1, dom := i * 2num := nums[i]if ... Read More

Program to check all listed delivery operations are valid or not in Python

Arnab Chakraborty
Updated on 14-Oct-2021 11:45:32

178 Views

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 is picked up, and "D" means "delivery". And these letters are followed by the order id number. For example, "P6" indicates pick up order 6. We have to check whether orders list is valid or not based on these rules −We cannot delivery an order before pickupEvery pickup must be deliveredAn order which is already been picked up and also delivered cannot be picked up or delivered againSo, if the input is like orders = ... Read More

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

Arnab Chakraborty
Updated on 14-Oct-2021 11:42:09

400 Views

Suppose we have a list of heights of different buildings. A building with heights 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 heights 12 at index 2, from building height 10 at index 10 and from last building at index 5.To solve this, we will ... Read More

Advertisements