• + 0 comments

    The basic exercise is getting all subsequent arrays without repeating So you need to pass for all elements but don't need to create combinations that are not subsequently.. left to right, you can get this using a bigger array (I'll call move array) to move the edges Representing by {} in this example, for [ I'll call cut edge left, and for ] cut edge right,

    see this example. -> Passing through the array move

    // sum to verify if the sum is negative, // count to verify the quantity of negative sum int sum = 0, count = 0;

    //see {1,2,3,4,5}
    for (int i = 0; i < sizeOfArray; i++) { // move array
    	// the second array starts by the actual index
    	// {1,2,[3],4,5} -> example
    	for (int j = i; j < sizeOfArray; j++) { // edge left
    		sum = 0; 
    		// {1,2,[3,4,5]} -> example
    		// the third array starts by the actual index but goes only two j
    		for (int k = j; k < j; k++) { // right edge
    			// {1,2,[3,4],5} every loop the clip is more strict -> example
    			sum += array[k]
    		}
    		if (sum < 0) count++; // updates the count
    	}
    	
    }
    

    {[1,]2,3,4,5} -> {[1,2],3,4,5} -> {[1,2,3],4,5} => index = 0 {1,[2],3,4,5} -> {1,[2,3],4,5} -> {1,[2,3,4],5} => index = 1 .... {1,2,3,[4,]5} -> {1,2,3,[4,5]} => index = 3 until 4