Question bank › Backtracking
Dsa Backtracking Medium

Restricted Step Permutation

Find the lexicographically smallest permutation of the integers from 1 to N that starts with a given integer S, such that the absolute difference between any two adjacent elements in the permutation is either 1 or 2. Print the permutation as space-separated integers. If no such permutation exists, print 'None'. Example: Input: 4 1 Output: 1 2 3 4 (Explanation: |1-2|=1, |2-3|=1, |3-4|=1. All differences <= 2.)

Key concepts

backtrackingpermutations

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.