Cannot think how to approach

Cannot think how to approach and switch between arrays to get the max sum.

I watched some youtube videos and solved the question… understood how we need to solve the question… but I don’t understand why are we adding the smaller element to the sum and not the bigger element as at last we need the bigger sum right?

hi @Riya-Verma-1207263756078812, it not about adding small elements and big elements as every time at common points u r adding the max in your answer

but I want to know the logic behind the same, like if (arr[i] < brr[j]) { sum_of_arr += arr[i++]; } but if the value of brr[j] is greater we should’ve added that into the result na!

@Riya-Verma-1207263756078812, initially we are storing temporarily and at common points only we are adding to our ans … Just do a dry run once you’ll realise this

Hope this helps :slight_smile:

@Riya-Verma-1207263756078812, consider the case where there are more smaller elements which will add more to the sum till the common point

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.