Find the Longest Repeated Chord Section in a Song
Last updated: November 29, 2026
Quick Overview
Given a song as a sequence of chord tokens, return the length and start positions of the longest contiguous chord run that appears at least twice without the two occurrences overlapping, as a building block for detecting choruses and repeated sections.
Suno
November 29, 20260
0
0 solved
Given a song as a sequence of chord tokens, return the length and start positions of the longest contiguous chord run that appears at least twice without the two occurrences overlapping, as a building block for detecting choruses and repeated sections.
Song structure (verse, chorus, bridge) matters to Suno's models and to Studio tools that let users edit or regenerate a section. The interviewer looks for binary search on the answer plus rolling hash, correct handling of the non-overlap constraint, and verification against hash collisions.
What the Interviewer Expects
- Recognize monotonicity: if length L repeats, so does L - 1
- Binary search the length up to n // 2
- Rolling hash over token ids for O(1) window hashes
- Enforce non-overlap by comparing earliest occurrence
- Verify matches to rule out collisions
- State the complexity and a suffix-array alternative
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you tolerate one chord substitution between repeats?
- How would you find all repeated sections, not just the longest?
- How would this work on audio frames instead of symbolic chords?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of chord strings, for example C G Am F C G Am F Dm G. Output: (length, first_start, second_start) for the longest run occurring twice with first_start + length <= second_start, or `(...
High-Level Design
If a non-overlapping repeat of length L exists, cutting both copies gives one of length L - 1, so feasibility is monotone and binary search applies. For a fixed L, slide a polynomial rolling hash over...