We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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(inti=0;i<sizeOfArray;i++){// move array// the second array starts by the actual index// {1,2,[3],4,5} -> examplefor(intj=i;j<sizeOfArray;j++){// edge leftsum=0;// {1,2,[3,4,5]} -> example// the third array starts by the actual index but goes only two jfor(intk=j;k<j;k++){// right edge// {1,2,[3,4],5} every loop the clip is more strict -> examplesum+=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
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Subarray
You are viewing a single comment's thread. Return to all 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;
{[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