Question bank › Sorting
Dsa Sorting Medium

Canonical Circular Shift Sorter

For every string in a given list, its 'representative' is defined as the lexicographically smallest string among all its possible circular shifts. Sort the original strings based on their representatives. If two strings have the same representative, sort them by the original strings themselves. Example: Input: 'dbac acdb' Shifts of 'dbac': dbac, bacd, acdb, cdba -> Min: 'acdb' Shifts of 'acdb': acdb, cdba, dbac, bacd -> Min: 'acdb' Both have same representative. Sort by original: 'acdb' then 'dbac'. Output: 'acdb dbac'

Key concepts

sortingstringscyclic-shifts

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.