#301 Finding a Subarray with a Given Sum

Companies:
Yandex
Themes:
AlgorithmsArraysPractice

An array of integers and a number x are given as input. Find any subarray whose elements sum to x. Return the boundaries of this subarray or an empty array if this is impossible.

[5,1,2,1], x = 4 -> (1,3) // 1 + 2 + 1 = 4

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in