Algorithm to find largest and smallest summing sub-array from an array
A lot of coding tests by various companies ask these kind of questions. Today we will have a look at one such question and an approach/algorithm to solve such problem.
Algorithm to find largest and smallest summing sub-array from given array
Problem Statement: – Given an Array A of numbers, find sub-arrays (array slices) with the largest and smallest sum of their numbers.
For eg; consider the below array
[1,2,3] – In this array, the largest sum array slice is  and smallest sum array slice is . Your program will be given an array as input, your job is to find all permutations of sub-arrays possible out of that array and print sub-arrays with largest and smallest sums.
One of the various possible solutions to this problem is given below:-
Below iframe will show the output of the html code embedded in this post.
Just click on generate button above to see the output of the above code.
Any suggestions, to improve this approach are most welcome. We want to create interactive sessions around our tech blogs.