The Spiritual Side of the Coronavirus Epidemic By Vibhushri

Epidemics brought about by contagious diseases have always been around. The coronavirus epidemic is the latest episode of this common occurrence that has impacted humanity since the earliest time…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Split Array Largest Sum

Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these m subarrays.

Solution : This is a great problem and consists of many subproblems. Lets consider the subproblems first.

SubProblem 1: Given an array of length A and a given number of cuts c can we use c cuts to divide Array A into c + 1 parts such that the maximum sum of any of the part is below or equal to a given number say x.

Sub Problem 2: Given a boolean array B find the first index where it returns true

Solution: This is a pretty basic Binary Search question

Now lets come back to our problem. We are given the number of cuts.Lets say we have the given array A [1, 2, 3, 4, 5]. and cuts c = 2

For any number of cuts the minimum maximum sum of any part is 5 and maximum maximum sum of any part is 15 when cut = 1

so the range of the maximum sum of the array is between [5, 15]

Lets start with the input parameter as 5 for subproblem 1 so

B[5] = False

B[6] = True

B[7] = True infact for every x ≥6 B[x] will be True

so we have B array now we do binary search in this array to find the first index when it is true , that index will be the value at which cutting A with c cuts is possible and it is the minimum val of all the array sums of each part as it is the first true element

Add a comment

Related posts:

The Importance of School Choice Programs in Quality Education

TNT Academy is a Stone Mountain, Georgia, private school that offers a curriculum-based education to students in and around Gwinnett County. With a pulse on the differences between private and public…

Langkawi Trip Report

At the end of July 2019, my wife and I spent 5 nights in the beautiful island of Langkawi in Malaysia. It had been a long time since our last international trip (Oct 2018) and we wanted a short…

Trivial Pursuit

Trivial Pursuit the board game divides the world of knowledge into six categories; six wedges of cheese for six spaces in a wheel with six spokes. In pursuit of rounded knowledge from Trivial Pursuit…