Dsa
Two Pointers
Easy
Social Media Content Engagement
Given an array of integers where each integer represents the number of likes on a social media post for the last N days, your task is to determine the maximum number of consecutive days such that the sum of likes does not exceed a certain limit K.\n\nInput Format:
- The first line contains two integers N (number of days) and K (maximum allowed sum).
- The second line contains N space-separated integers representing the likes.\n\nOutput Format:
- A single integer representing the length of the longest subarray with a sum not exceeding K.\n\nExample:
Input:
5 7
1 2 3 4 5\nOutput:
3
(The subarray [1,2,3] has sum of 6 which is maximum without exceeding 7)
Key concepts
two_pointerssliding_windowarray
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