Server Side Programming Articles - Page 1686 of 2646

Find minimum time to finish all jobs with given constraints in C++

Arnab Chakraborty
Updated on 25-Jul-2020 09:34:02

437 Views

ConceptWith respect of a given array of jobs with different time requirements, there exists k identical assignees available and we are also provided how much time an assignee consumesto do one unit of the job. Our task is to determine the minimum time to complete all jobs with following constraints.The first constraint is that an assignee can be assigned only contiguous jobs.Here, for example, an assignee can be assigned jobs at position 1 and 2, but not at position 3, in an array.The second constraint is that two assignees cannot share (or co-assigned) a job, that means, a job cannot ... Read More

Find minimum s-t cut in a flow network in C++

Arnab Chakraborty
Updated on 25-Aug-2020 12:16:47

397 Views

Suppose we have following flow network. As we know an s-t cut is a cut that requires the source s node and a sink t node to be in different subsets, and it includes edges going from the source set to the sink side. Here the capacity of an s-t cut is represented by the sum of each edge capacity in the cut-set. Here we have to find minimum capacity s-t cut of the given network. Here the expected output is all edges of the minimum cut.So, if the input is likethen the output will be [(1, 3), (4, 3), ... Read More

Find minimum adjustment cost of an array in C++

Arnab Chakraborty
Updated on 25-Jul-2020 09:22:58

457 Views

ConceptWith respect of a given array of positive integers, we replace each element in the array so that the difference between adjacent elements in the array is either less than or equal to a given target. Now, our task to minimize the adjustment cost, that is the sum of differences between new and old values. So, we basically need to minimize Σ|A[i] – Anew[i]| where 0 ≤ i ≤ n-1, n is denoted as size of A[] and Anew[] is denoted as the array with adjacent difference less than or equal to target. Let all elements of the array is ... Read More

Find memory conflicts among multiple threads in C++

Arnab Chakraborty
Updated on 25-Aug-2020 12:19:14

227 Views

Suppose we have a RAM and that RAM is organized in blocks. there are multiple processes running on the system. We have to keep in mind that every process gets following information, (Thread T, Memory Block M, time t, R/W) This indicates the thread T was implementing memory block M at given time t and operation could be either read(R) or write(W).The following case is indicating whether it is memory conflict or not −More than one read operations at the same location are not the reason of conflict.When writing operation is being performed between x+5 to x-5 to location of ... Read More

Find median of BST in O(n) time and O(1) space in C++

Arnab Chakraborty
Updated on 25-Jul-2020 16:43:10

931 Views

ConceptWith respect of a given Binary Search Tree(BST), our task is to determine median of it.For even no. of nodes, median = ((n/2th node + (n+1)/2th node) /2 For odd no. of nodes, median = (n+1)/2th node.For given BST(with odd no. of nodes) is −       7       / \      4   9    / \   / \   2  5  8  10Inorder of Given BST will be : 2, 4, 5, 7, 8, 9, 10 So, here median will 7.For given BST(with even no. of nodes) is −         7   ... Read More

Find maximum sum of triplets in an array such than i < j < k and a[i] < a[j] < a[k] in C++

Ravi Ranjan
Updated on 01-Jul-2025 15:35:10

2K+ Views

In this article, we have an array of positive integers of size n. Our task is to calculate the maximum sum of triplet ( ai + aj + ak ) such that 0 sum = 12 3 6 10 => sum = 19 3 4 10 => sum = 17 4 5 10 => sum = 19 2 5 10 => sum = 17 Maximum sum = 19 Finding maximum sum of triplets in an array such than i < j < k and a[i] < a[j] < a[k]Here are the approaches ... Read More

Find maximum points which can be obtained by deleting elements from array in C++

Arnab Chakraborty
Updated on 25-Jul-2020 08:52:43

167 Views

ConceptWith respect of a given array A having N elements and two integers l and r where, 1≤ ax ≤ 105 and 1≤ l≤ r≤ N. We can select any element of the array (let’s say ax) and delete it, and also delete all elements equal to ax+1, ax+2 … ax+R and ax-1, ax-2 … ax-L from the array. This step will cost ax points. Our task is to maximize the total cost after deleting all the elements from the array.Input2 1 2 3 2 2 1 l = 1, r = 1Output8Here, we choose 2 to delete, then (2-1)=1 ... Read More

Find maximum operations to reduce N to 1 in C++

Arnab Chakraborty
Updated on 25-Jul-2020 08:49:31

154 Views

ConceptWith respect of given two numbers P and Q ( P and Q can be up to 10^6 ) which forms a number N = (P!/Q!). Our task is to reduce N to 1 by performing maximum number of operations possible. Remember, in each operation, one can replace N with N/X if N is divisible by X. Determine the maximum number of operations that can be possible.InputA = 7, B = 4Output4ExplanationN is 210 and the divisors are 2, 3, 5, 7InputA = 3, B = 1Output2ExplanationN is 6 and the divisor are 2, 3.MethodIt has been observed that factorization ... Read More

Find maximum N such that the sum of square of first N natural numbers is not more than X in C++

Arnab Chakraborty
Updated on 25-Jul-2020 08:45:08

496 Views

ConceptWith respect of a given integer X, our task is to determine the maximum value N so that the sum of first N natural numbers should not exceed X.InputX = 7Output22 is the maximum possible value of N because for N = 3, the sum of the series will exceed X i.e. 1^2 + 2^2 + 3^2 = 1 + 4 + 9 = 14InputX = 27Output33 is the maximum possible value of N because for N = 4, the sum of the series will exceed X i.e. 1^2 + 2^2 + 3^2 + 4^2 = 1 + 4 + ... Read More

Find maximum length Snake sequence in C++

Arnab Chakraborty
Updated on 25-Jul-2020 08:42:11

379 Views

ConceptWith respect of a given grid of numbers, determine maximum length Snake sequence and display it. It has been observed that if multiple snake sequences exist with the maximum length, display any one of them.Actually, a snake sequence is made up of adjacent numbers in the grid so that for each number, the number on the right or the number below it is either +1 or -1 its value. Here, for instance, if we are at location (a, b) in the grid, we can either move right i.e. (a, b+1) if that number is ± 1 or move down i.e. ... Read More

Advertisements