id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > partialSumSunflowerAustralia
prev  |  next  |  chance

Write a method that returns the "partial sum" of an array of integers. So each position in the array that is returned will contain the sum of all the integers in the original array up to and including that position. Except, if a number is repeated consecutively, only count the first time it occurs in that batch of consecutive occurrences. If that number occurs again later (after the batch of consecutive occurrences) it will count as normal. For example: {5, 7, 3, 3, 3, 5, 5, 3, 7} will return {5, 12, 15, 15, 15, 20, 20, 23, 30} since the third and fourth 3's do not add to the running total because they are part of a consecutive batch of 3's. The 3rd 5 is also not added. But the 3 after the two 5's IS added since it is not part of a batch. Look at the test data for further examples.


partialSumSunflowerAustralia([3, 7, 2, 2, 2, 2, 4, 2, 2, 6, 6, 8]) → [3, 10, 12, 12, 12, 12, 16, 18, 18, 24, 24, 32]
partialSumSunflowerAustralia([5, 3, 1, 100]) → [5, 8, 9, 109]
partialSumSunflowerAustralia([6000, 4000, -10000, -2, 4, 2, 2, 1]) → [6000, 10000, 0, -2, 2, 4, 4, 5]

...Save, Compile, Run (ctrl-enter)

public int[] partialSumSunflowerAustralia(int[] nums) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 290

Copyright Nick Parlante 2017 - privacy