Company: infosys

Difficulty: medium

Problem Statement

Maximum Points Covered by a Length-L Window You are given N point positions on a number line, a window length L , and a positive integer K . Select as many points as possible such that: every selected position has the same remainder when divided by K ; and the largest selected position minus the smallest selected position is at most L . Print the maximum possible number of selected points. Input The first line contains N . The second line contains L . The third line contains K . The fourth line contains N integers pts[0] ... pts[N-1] . Output Print the maximum valid subset size. Constraints 1 <= N <= 200000 0 <= L <= 10^9 1 <= K <= 10^9 0 <= pts[i] <= 10^9 Duplicate positions represent distinct points and may all be selected. Examples Input: 7 6 3 1 4 7 10 13 2 5 Output: 3 Positions 1, 4, and 7 all have remainder 1 modulo 3 and span exactly 6. Input: 6 4 2 2 4 6 8 1 3 Output: 3 Positions 2, 4, and 6 are valid. Notes The distance comparison is inclusive. A subset

More infosys OA questionsInterview experiences