Deloitte interview question

subarray coding question with medium difficulty