6 kyu
The maximum sum value of ranges -- Simple version
1,452 of 2,747myjinxin2015
Description:
When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said
Description:
Given an array arr
that contains some integers(positive, negative or 0), and a range
list such as [[start1,end1],[start2,end2],...]
, start and end are the index of arr
and start always less than end. Your task is to calculate the sum value of each range (start index and end index are both inclusive), and return the maximum sum value.
For example:
Given arr = [1,-2,3,4,-5,-4,3,2,1],
range = [[1,3],[0,4],[6,8]]
should return 6
calculation process:
range[1,3] = arr[1]+arr[2]+arr[3] = 5
range[0,4] = arr[0]+arr[1]+arr[2]+arr[3]+arr[4] = 1
range[6,8] = arr[6]+arr[7]+arr[8] = 6
So the maximum sum value is 6
Note:
arr
/$a
always has at least 5 elements;range
/$range
/ranges
always has at least 1 element;- All inputs are valid;
- This is a simple version, if you want some challenge, please try the challenge version.
Some Examples
maxSum([1,-2,3,4,-5,-4,3,2,1],[[1,3],[0,4],[6,8]]) === 6
maxSum([1,-2,3,4,-5,-4,3,2,1],[[1,3]]) === 5
maxSum([1,-2,3,4,-5,-4,3,2,1],[[1,4],[2,5]]) === 0
Fundamentals
Similar Kata:
Stats:
Created | Nov 29, 2016 |
Published | Nov 29, 2016 |
Warriors Trained | 3836 |
Total Skips | 180 |
Total Code Submissions | 7513 |
Total Times Completed | 2747 |
JavaScript Completions | 1452 |
Haskell Completions | 97 |
PHP Completions | 139 |
Ruby Completions | 107 |
Python Completions | 972 |
C Completions | 68 |
Total Stars | 48 |
% of votes with a positive feedback rating | 94% of 488 |
Total "Very Satisfied" Votes | 433 |
Total "Somewhat Satisfied" Votes | 52 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 10 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |