Given an integer num, return an array consisting of positive consecutive integers that sum to num. There may be multiple sequences that work; return the sequence with the largest number of consecutive integers. Return an empty array if there are no solutions.
Example:
maxConsecutiveSum(45) returns [1,2,3,4,5,6,7,8,9].
Notice that [14,15,16] also add to 45 but there is a solution that has more numbers in it.
public class maxConsecutiveSum{
public static int[] maxConsecutiveSum(int num){
//code goes here
return [];
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
public class SolutionTest {
@Test
public void testSomething() {
assertEquals(maxConsecutiveSum(45), [1,2,3,4,5,6,7,8,9]);
assertEquals(maxConsecutiveSum(3), [1,2]);
assertEquals(maxConsecutiveSum(2), []);
assertEquals(maxConsecutiveSum(182), [44,45,46,47]);
}
}