Dsa
Arrays
Hard
Contiguous Subarray Sum
Given an array of integers, you need to find a contiguous subarray whose sum equals a target value. Print the starting and ending indices of the subarray (zero-based, inclusive); if no such subarray exists, print -1. The input consists of two lines; the first line contains an integer `target`, and the second line contains the integers of the array.
Example:
Input:
5
1 2 3 4 5
Output:
0 1
Key concepts
arraysprefix sumsubarrays
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now