Palindrome Partitioning
Given a string s, partition s such that every substring is a palindrome Return all possible palindrome partitioning of s Example: s = "aab" => [["a","a","b"],["aa","b"]]
Cut where the prefix already mirrors, then recurse on what is left. I undo each cut before sliding it right.
Examples
You write
partition(s: str)
Example 1
- Input
- s = "aab"
- returns
- [["a","a","b"],["aa","b"]]
Example 2
- Input
- s = "a"
- returns
- [["a"]]
The pattern behind it
Strings
I reach for it when
- The input is text and the answer is a count, a substring or a new string.
- You need to compare, reverse or rebuild characters.
Say this before you type. Say which array pattern the string is hiding before you touch a character.
All 51 Strings problemsBacktracking
I reach for it when
- The question asks for all combinations, permutations or placements.
- You make a choice, explore it, and may need to take it back.
Say this before you type. Say the choice, the stopping rule, and the earliest moment you can prune.
All 15 Backtracking problems
Meet Coco
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.