Deloitte Interview Question

subarray coding question with medium difficulty