Question: Write a Java program for the following Our delivery riders need to complete longer and longer routes. They need a break! Find the optimal break

Write a Java program for the following

Our delivery riders need to complete longer and longer routes. They need a break! Find the optimal break for our rider according to the specs below:

You are given an array of integers of length n for a rider. The integer at index i symbolizes the time allocated to her or his i'th task in minutes. The optimal time for a break is between two tasks i and i+1, when the sum of all tasks from 0 to i equals the sum i+1 to n.

Write a method that returns index i where the condition above is met. If there is no such index the rider is not awarded a break and we return null. Consider the runtime complexity of your solution!

Example:

Input [1, 4, 1, 3, 1] -> Output 1

Input [1, 4, 1, 3] -> Output null

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!