Dsa
Hashing
Easy
Relative Signal Echoes
In digital signal processing, an 'echo' is a sequence of values that follows the same relative progression as another. Two sequences [a, b, c] and [x, y, z] are echoes if (b-a) == (y-x) and (c-b) == (z-y). Given a stream of N integers and a pattern length K, find the frequency of the most common relative progression.
Input Format:
- Line 1: N and K.
- Line 2: N space-separated integers.
Output Format:
- An integer representing the maximum frequency of any relative progression.
Example:
Input:
6 3
1 2 4 10 11 13
Output:
2
(Explanation: [1,2,4] -> diffs (1,2). [10,11,13] -> diffs (1,2). Count is 2.)
Key concepts
hashingarrayspattern matching
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