Find Maximum Subarray Minimum Product in Python

Arnab Chakraborty
Updated on 08-Oct-2021 07:18:59

307 Views

Suppose we have an array nums, we have to find the maximum min-product of each non-empty subarray of nums. Since the answer can be big enough, return it in modulo 10^9+7. The min-product of the array is equal to the minimum value in the array multiplied by the sum of the array. So if we have an array is like [4, 3, 6] (minimum value is 3) has a min-product of 3*(4+3+6) = 3*13 = 39.So, if the input is like nums = [2, 3, 4, 3], then the output will be 30 because we can get subarray [3, 4, ... Read More

Find Maximum Distance Between a Pair of Values in Python

Arnab Chakraborty
Updated on 08-Oct-2021 07:16:10

697 Views

Suppose we have two arrays (non-growing) nums1 and nums2. The index pair (i, j) with 0

Check if String can be Split into Descending Consecutive Values in Python

Arnab Chakraborty
Updated on 08-Oct-2021 07:12:02

262 Views

Suppose we have a string s with only numbers. We have to check whether we can split s into two or more non-empty substrings such that the numerical values of those substrings are in non-increasing sequence and the difference between numerical values of every two adjacent substrings is 1. So for example, if the string is s = "0080079" we can split it into ["0080", "079"] with numerical values [80, 79]. And the values are in descending order and adjacent values differ by 1, so this way is valid. We have to check whether it is possible to split s ... Read More

Find Maximum Element After Decreasing and Rearranging in Python

Arnab Chakraborty
Updated on 08-Oct-2021 07:07:56

218 Views

Suppose we have an array called arr. We have to perform some operations on arr so that it satisfies these conditions −The first element in arr must be 1.The absolute difference between any 2 adjacent elements must be at most 1.And there are two operations. We can perform these two types of operations any number of times −Decrease any value of arr to a smaller positive number.Rearrange the elements of arr to be in any order.We have to find the maximum possible value in arr after performing the operations to satisfy the given conditions.So, if the input is like arr ... Read More

Implement Seat Reservation Manager in Python

Arnab Chakraborty
Updated on 08-Oct-2021 07:03:49

2K+ Views

Suppose we have to design a system that manages the reservation state of n seats. The seats are numbered from 1 to n. So we have to implement the SeatReserveManager class, with these functions −Constructor that takes n as input and initializes the object that will manage n seats numbered from 1 to n. Initially all seats are available.reserve(), this will fetch the smallest-numbered unreserved seat, then reserves it, and returns its number.unreserve(seatNumber), this will unreserve one reserved seat with the given seatNumber.So, if the input is likeobj = SeatReserveManager(7)obj.reserve()obj.reserve()obj.reserve()obj.unreserve(2)obj.unreserve(5)obj.reserve()obj.reserve()then the output will be 1, 2, 3, 2, 5, initially ... Read More

Find Closest Subsequence Sum in Python

Arnab Chakraborty
Updated on 08-Oct-2021 07:00:04

488 Views

Suppose we have an array nums and another value goal. We want to select a subsequence of nums such that the sum of its elements is the nearest to goal. So in other words, if the sum of the subsequence's elements is s, then we want to minimize the absolute difference |s - goal|.So we have to find the minimum possible value of |s - goal|. So, if the input is like nums = [8, -8, 16, -1] goal = -3, then the output will be 2 because select the subsequence [8, -8, -1], with a sum of -1. The ... Read More

Find Longest Substring of All Vowels in Order in Python

Arnab Chakraborty
Updated on 07-Oct-2021 13:18:48

652 Views

Suppose we have a string s with only English vowels, we have to find the length of the longest beautiful substring of s. If we cannot find such substring then, return 0. A string is said to be beautiful if it satisfies the following conditions −Each of the 5 vowels must appear at least once in it.Letters must be sorted in alphabetical sequenceSo, if the input is like s = "aaioaaaaeiiouuooaauu", then the output will be 10 because the substring is "aaaaeiiouu" which is beautiful.To solve this, we will follow these steps −vowels := a list of all vowels ['a', ... Read More

Find Frequency of the Most Frequent Element in Python

Arnab Chakraborty
Updated on 07-Oct-2021 13:13:52

650 Views

Suppose we have an array nums and another value k. In one operation, we can select an index of nums and increase the element at that index by 1. We have to find the maximum possible frequency of an element after performing at most k number of operations.So, if the input is like nums = [8, 3, 6], k = 9, then the output will be 3 because we can update 3 by 5, 6 by 2, to make it [8, 8, 8] so after 7 operations we have maximum frequency 3.To solve this, we will follow these steps −sort ... Read More

Find Maximum Ice Cream Bars in Python

Arnab Chakraborty
Updated on 07-Oct-2021 13:08:09

688 Views

Suppose we have an array costs with n elements, where costs[i] is the price of the ith ice cream bar in coins. We initially have c number coins to spend, and we want to buy as many ice cream bars as possible. We have to find the maximum number of ice cream bars we can buy with c coins.So, if the input is like costs = [3, 1, 4, 5, 2], c = 10, then the output will be 4 because we can buy ice cream bars at indices 0, 1, 2, 4 for a total price of 3 + ... Read More

Find Maximum XOR for Each Query in Python

Arnab Chakraborty
Updated on 07-Oct-2021 13:04:49

298 Views

Suppose we have an array which is presorted called nums of size n and also have one value b. We want to perform the following query n times −Search for a non-negative value k < 2^m such that XOR of all elements in nums and k is maximized. So k is the answer to the ith query.Remove the last element from the current array nums.We have to find an array answer, where answer[i] is the answer to the ith query.So, if the input is like nums = [0, 1, 1, 3], m = 2, then the output will be [0, ... Read More

Advertisements