How would you like to learn today?
Visualize algorithms in real time, explore them step by step, or challenge yourself with a test.Choose a path to focus—or scroll down to preview all options.
Visualize the algorithm step-by-step with interactive animations in real time.
Read the full explanation, examples, and starter code at your own pace.
Drag and arrange the algorithm steps in the correct execution order.
🧠 Select Active to activate
Follow every state change, comparison, and transformation as the execution unfolds in real time.
📖 Select Passive to activate
Problem Statement:
Given a string s, the task is to partition the string into all possible palindrome substrings. We need to find and return all possible valid partitions where each substring is a palindrome.
The ispalindrome function checks whether a given substring of string s is a palindrome.
s: The input string.start: The starting index of the substring.end: The ending index of the substring.false, indicating the substring is not a palindrome.true and prints the palindrome substring.The calculate function recursively generates all valid partitions of the input string s.
index: The current index in the string.t: A vector of vectors that stores the valid palindrome partitions.s: The input string.path: A vector that stores the current partition path.index.index to i is a palindrome, we add it to the path.index and the current path.index reaches the end of the string, we’ve found a valid partition, and we add it to the result (t).path.This is the main function that initializes the process of palindrome partitioning.
s: The input string.t) to store the valid palindrome partitions.path) to store the current partition path.calculate function is called with initial parameters to start the recursive partition generation process.t containing all valid palindrome partitions.Input:
s = "aab"
Output:
[["a", "a", "b"], ["aa", "b"]]
Explanation:
The string "aab" can be partitioned in two valid ways:
"a", "a", "b""aa", "b"Input:
s = "a"
Output:
[["a"]]
Explanation:
The string "a" is already a palindrome, so the only partition is itself.
Input:
s = "racecar"
Output:
[["r", "a", "c", "e", "c", "a", "r"], ["racecar"]]
Explanation:
The string "racecar" can be partitioned in two valid ways:
"r", "a", "c", "e", "c", "a", "r""racecar" (the whole string is a palindrome)Input:
s = "abc"
Output:
[["a", "b", "c"]]
Explanation:
Since no two characters form a valid palindrome substring except for the single characters, the only valid partition is each character individually.
Input:
s = "aabb"
Output:
[["a", "a", "b", "b"], ["aa", "b", "b"], ["a", "a", "bb"]]
Explanation:
The string "aabb" can be partitioned into the following valid palindrome partitions:
"a", "a", "b", "b""aa", "b", "b""a", "a", "bb"🎯 Select Challenge to activate
Drag and arrange the algorithm steps in the correct execution order instead of spending time typing code letter by letter.
The algorithm is divided into three logical parts. Carefully rearrange each section in the correct order to form a complete and valid solution.
Understand Below AlgorithmGreen text means the instruction is placed in the correct position.
Red text means the instruction is in the wrong position.
Instructions with the same background color indicate particular blocks start and end.
A tick mark means the instruction is correct and locked.
🔒 Locked steps cannot be moved. Only unlocked steps are draggable.
🔊 Enable sound for swap feedback and completion effects.