Found 26504 Articles for Server Side Programming

Pizza With 3n Slices in C++

Arnab Chakraborty
Updated on 09-Jun-2020 07:07:44

331 Views

Suppose there is a pizza with 3n slices of varying size, I and my two friends will take slices of pizza as follows −I shall pick any pizza slice.My friend Amal will pick next slice in anti clockwise direction of my pick.My friend Bimal will pick next slice in clockwise direction of my pick.Repeat these steps until there are no more slices of pizzas.Sizes of Pizza slices is represented by circular array slices in clockwise direction. We have to find the maximum possible sum of slice sizes which I can have.So, if the input is like [9, 8, 6, 1, ... Read More

Maximum Performance of a Team in C++

Arnab Chakraborty
Updated on 09-Jun-2020 07:00:46

265 Views

Suppose there are n engineers. They are numbered from 1 to n and we also have two arrays: speed and efficiency, here speed[i] and efficiency[i] represent the speed and efficiency for the ith engineer. We have to find the maximum performance of a team composed of at most k engineers. The answer may be very large so return it modulo 10^9 + 7.Here the performance of a team is the sum of their engineers' speeds multiplied by the minimum efficiency among their engineers.So, if the input is like n = 6, speed = [1, 5, 8, 2, 10, 3], efficiency ... Read More

Frog Position After T Seconds in C++

Arnab Chakraborty
Updated on 09-Jun-2020 06:59:41

365 Views

Suppose we have one undirected tree consisting of n vertices. The vertices are numbered from 1 to n. Now a frog starts jumping from the vertex 1. The frog can jump from its current vertex to another non-visited vertex if they are adjacent, in one second. The frog can not jump back to a visited vertex. In case the frog can jump to several vertices it jumps randomly to one of themwhere the probability is same, otherwise, when the frog can not jump to any non-visited vertex it jumps forever on the same vertex.The tree is given as an array ... Read More

Maximum Sum BST in Binary Tree in C++

Arnab Chakraborty
Updated on 09-Jun-2020 06:56:02

441 Views

Suppose we have a binary tree root, we have to find the maximum sum of all nodes of any subtree which is also a Binary Search Tree (BST).So, if the input is like, then the output will be 20, this is the sum of all nodes in the selected BST.To solve this, we will follow these steps −Create one block called Data, this will hold some members like sz, maxVal, minVal, ok, sum. Also define one initializer for data, that will take in this order (sz, minVal, maxVal, ok, and set sum as 0)ret := 0Define a method called solve(), ... Read More

Largest Multiple of Three in C++

Arnab Chakraborty
Updated on 09-Jun-2020 06:53:06

157 Views

Suppose we have one array of digits, we have to find the largest multiple of three that can be formed by concatenating some of the given digits in any order as we want. The answer may be very large so make it as string. If there is no answer return an empty string.So, if the input is like [7, 2, 8], then the output will be 87To solve this, we will follow these steps −Define one 2D array d, there will be three rowssort the array digitssum := 0for initialize i := 0, when i < size of digits, update ... Read More

Count All Valid Pickup and Delivery Options in C++

Arnab Chakraborty
Updated on 08-Jun-2020 11:41:30

212 Views

Suppose we have a list of n orders, in each order there are pickup and delivery services. We have to count all valid pickup/delivery possible sequences such that delivery[i] is always after the pickup[i]. As the answer may very large, we will return it modulo 10^9 + 7.So, if the input is like 2, then the output will be 6, as All possible orders are (P1, P2, D1, D2), (P1, P2, D2, D1), (P1, D1, P2, D2), (P2, P1, D1, D2), (P2, P1, D2, D1) and (P2, D2, P1, D1). And the order (P1, D2, P2, D1) is not valid ... Read More

Construct Target Array With Multiple Sums in C++

Arnab Chakraborty
Updated on 08-Jun-2020 11:38:27

142 Views

Suppose we have an array of integers target. From a starting array A consisting of all 1's, we can perform the following procedure −Consider x be the sum of all elements currently in our array.Choose index i, in range 0 to n, where n is the size of the array and set the value of A at index i to x.We can repeat this procedure as many times as we need.We have to check whether it is possible to make the target array from A otherwise return False.So, if the input is like [3, 9, 5], then the output will ... Read More

Jump Game IV in C++

Arnab Chakraborty
Updated on 08-Jun-2020 11:37:44

348 Views

Suppose we have an array of integers called arr. We are initially at index 0. In one step we can jump from index i to i + x where: i + x < n. i - x where: i - x >= 0. j where: arr[i] and arr[j] are same and i and j are not same. Here n is the size of array. We have to find the minimum number of steps to reach the last index of the array.So, if the input is like, then the output will be 3, We need three jumps from index 0 to ... Read More

Jump Game V in C++

Arnab Chakraborty
Updated on 08-Jun-2020 11:34:51

624 Views

Suppose we have an array of integers called arr and an integer d. In one step we can jump from index i to −i + x where: i + x < n and x in range 1 to d.i - x where: i - x >= 0 and x in range 1 to d.Here n is the size of array. In addition, we can only jump from index i to index j when arr[i] > arr[j] and arr[i] > arr[k] for all indices k between i and j. We can choose any index of the array and start the jumping. ... Read More

Minimum Difficulty of a Job Schedule in C++

Arnab Chakraborty
Updated on 08-Jun-2020 11:31:55

370 Views

Suppose we want to schedule a list of tasks in d days. The tasks are dependent so, to work on the i-th task, we have to finish all the tasks j where 0 0, then −return 1^6if dp[idx, k] is not equal to -1, then −return dp[idx, k]maxVal := 0ret := inffor initialize i := idx, when i < size of v, update (increase i by 1), do −maxVal := maximum of v[i] and maxValret := minimum of ret and maxVal + solve(v, i + 1, k - 1, dp)dp[idx, k] := retreturn retFrom the main method do the ... Read More

Advertisements