DSA interview question
A word-game app awards bonus points when a word can be cut into pieces that are all palindromes (read the same both ways). For a given word, the app wants every way to cut it so that each piece is a palindrome. For "aab", that's a | a | b and aa | b. Backtracking tries every possible first piece, keeps only palindromic ones, and recursively partitions the rest of the string.
Example: "aab" → [a,a,b], [aa,b].
vector<vector<string>> partition(const string& s);
| Input | Output | Explanation |
|---|---|---|
"aab" | [a,a,b] [aa,b] | |
"a" | [a] | |
"aba" | [a,b,a] [aba] | |
"abba" | [a,b,b,a] [a,bb,a] [abba] | |
"ab" | [a,b] | Single letters are always palindromes |
(Confirm: every piece must be a non-empty palindrome; the pieces must cover the whole string in order; n is at most 16.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in