Algorithm to find largest and smallest summing sub-array from an array

0 / 1700
sub-array largest and smallest sum

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 [3] and smallest sum array slice is [1]. 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:-

ID provided is not a Gistpen repo.

 

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.

 

Comments

comments


An avid reader, responsible for generating creative content ideas for golibrary.co. His interests include algorithms and programming languages. Blogging is a hobby and passion.

Related Posts