Programming Articles - Page 1023 of 3366

Program to find maximum number of consecutive values you can make in Python

Arnab Chakraborty
Updated on 07-Oct-2021 12:14:35

467 Views

Suppose we have an array called coins with n elements, and it is representing the coins that we own. The value of the ith coin is denoted as coins[i]. We can make some value x if we can select some of our n coins such that their values sum up to x. We have to find the maximum number of consecutive values that we can get with the coins starting from and including 0.So, if the input is like coins = [1, 1, 3, 4], then the output will be 10, because0 = []1 = [1]2 = [1, 1]3 = ... Read More

Program to find out the number of accepted invitations in Python

Arnab Chakraborty
Updated on 07-Oct-2021 12:21:32

333 Views

Suppose there are m boys and n girls, and m = n. There is a party incoming, and each boy has to go with a girl to that party. So, the boys invite all the girls and a girl can accept one invitation only. We have to find out the total number of invitations from the boys that the girls can accept. The input is given in a m x n matrix, where each cell position i, j denotes if the boy i has sent a letter to girl j. If a cell is 1 it means that an invitation ... Read More

Program to find out the number of pairs of equal substrings in Python

Arnab Chakraborty
Updated on 07-Oct-2021 12:04:37

356 Views

Suppose we are given two strings, both made of lowercase alphabets. We have to find out the number of quadruples (p, q, r, s) satisfying the given conditions −0

Program to sort out phrases based on their appearances in Python

Arnab Chakraborty
Updated on 07-Oct-2021 11:59:00

135 Views

Suppose, we are given two lists; 'phrases' that contain a few selected phrases and 'sentences' that contain several sentences that may or may not contain the phrases from the other list. We have to find out if the various phrases in the first list appear in the second list and sort the first list phrases based on their appearances in the second list. We return the sorted list 'phrases' as output.So, if the input is like phrases = ['strong', 'durable', 'efficient'], sentences = ['the product is durable and efficient', 'strong and durable', 'it is efficient', 'like it because it is ... Read More

Program to find out the buildings that have a better view in Python

Arnab Chakraborty
Updated on 07-Oct-2021 11:52:59

334 Views

Suppose, we are provided with an array that contains the heights of different buildings. The buildings are located on a line, and a building has a better view if it is not obstructed by another taller building. So provided the array containing heights, we have to find out the buildings that do not have other taller buildings to obstruct the view from them. The indices are returned from the array that satisfies the criteria.So, if the input is like height = [5, 6, 8, 7], then the output will be [2, 3]. The buildings in array index 0 and 1 ... Read More

Program to design a queue that moves the most recently used element to the end of it in Python

Arnab Chakraborty
Updated on 07-Oct-2021 11:49:46

472 Views

Suppose, we are asked to design a queue that moves the most recently used element to the end of it. The queue will be initialized with integer numbers 1 to n. Now we have to build a function so that whenever it is called, it moves the value from the position given as its input to the end of the queue. We will call the function multiple times, and the function will return the value currently at the end of the queue while performing its moving task.So, if the queue is initialized with a value n = 5, or it ... Read More

Program to find out the sum of the maximum subarray after a operation in Python

Arnab Chakraborty
Updated on 07-Oct-2021 11:44:21

200 Views

Suppose, we are given an array containing integer numbers. We can perform an operation where we can replace the value of array[i] with its squared value; or array[i] * array[i]. Only one operation of this kind is permitted and we have to return the sum of the maximum possible subarray after the operation. The subarray cannot be empty.So, if the input is like array = [4, 1, -2, -1], then the output will be 17.If we replace the value in array[0] with its squared value, the array becomes [16, 1, -2, -1]. The maximum subarray that is possible from this ... Read More

Program to restore the array from adjacent pairs in Python

Arnab Chakraborty
Updated on 07-Oct-2021 11:39:28

265 Views

Suppose we have a 2D array called adPair of size n-1 where each adPair[i] has two elements [ui, vi] represents that the elements ui and vi are adjacent in an array called nums, in nums there are n unique elements. We have to find the array nums. If there are multiple solutions, return any of them.So, if the input is like adPair = [[3, 2], [4, 5], [4, 3]], then the output will be [2, 3, 4, 5]To solve this, we will follow these steps −my_map := an empty map to store list for different keysfor each pair (a, b) ... Read More

Program to find out distance between two nodes in a binary tree in Python

Arnab Chakraborty
Updated on 07-Oct-2021 11:33:05

795 Views

Suppose, we are given a binary tree and are asked to find the distance between two nodes in the binary tree. We find out the edges between the two nodes like in a graph and return the number of edges or the distance between them. A node of a tree has the structure as below −data : right : left : So, if the input is likeand the nodes between which we have to find the distance between are 2 and 8; then the output will be 4.The edges between the two nodes 2 and 8 are: (2, ... Read More

Program to find k-th largest XOR coordinate value in Python

Arnab Chakraborty
Updated on 07-Oct-2021 11:19:54

192 Views

Suppose we have one m x n matrix. and another value k. Here the value of coordinate (a, b) of the matrix is the XOR of all matrix[i, j] where i in range (0 to a) and j in range (0 to b). We have to find the kth largest value (1-indexed) of all the coordinates of matrix.So, if the input is like5216And k = 1, then the output will be 7 because the value of coordinate (0, 1) is 5 XOR 2 = 7, and this is the largest oneTo solve this, we will follow these steps −m := ... Read More

Advertisements