Company: Springworks__

Difficulty: medium

Problem Statement

Smart Ad Injection System Problem Description You are building a system that decides when to inject ads into a video stream. You are handed a sorted list of candidate timestamps (in seconds) where an ad slot could go. To avoid annoying viewers, consecutive ads you actually schedule must be at least K seconds apart. Given the sorted candidate timestamps and the minimum required gap K , work out the largest number of ads you can schedule. Note: You always pick the first valid timestamp to maximize the count. Examples Example 1: Input: timestamps = [10, 20, 30, 40], K = 15 Output: 2 Explanation: Schedule an ad at 10. Can 20 work next? Gap (20-10)=10. Not enough (need 15). Can 30 work next? Gap (30-10)=20. That clears the bar, so schedule an ad at 30. Can 40 work next? Gap (40-30)=10. Not enough. Total shown: 2 (at 10 and 30). Example 2: Input: timestamps = [1, 2, 3, 10], K = 5 Output: 2 Explanation: Ad at 1. Next valid is 10 (diff 9). Total 2.

More Springworks__ OA questionsInterview experiences