Question bank › Hashing
Dsa Hashing Easy

Secret Ritual Chapters

A secret society uses sequences of gestures as handshakes. Two handshakes belong to the same 'Chapter' if one sequence is a cyclic shift of the other. Given several handshake sequences, determine how many unique Chapters are represented. Input Format: The first line contains an integer N, the number of handshakes. The next N lines each contain a comma-separated sequence of integers. Output Format: An integer count of unique Chapters. Example: Input: 3 1,2,3 2,3,1 1,3,2 Output: 2 (Explanation: [1,2,3] and [2,3,1] are cyclic shifts of each other, so they belong to Chapter A. [1,3,2] is not a cyclic shift of [1,2,3], so it belongs to Chapter B.)

Key concepts

canonical formcyclic shifthashing

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.