# 131. Palindrome Partitioning

### Description

Given a string *s*, partition *s* such that every substring of the partition is a palindrome.

Return all possible palindrome partitioning of *s*.

### Constraints

### Approach

### Links

* GeeksforGeeks
* [Leetcode](https://leetcode.com/problems/palindrome-partitioning/)
* [ProgramCreek](https://www.programcreek.com/2013/03/leetcode-palindrome-partitioning-java/)
* YouTube

### **Examples**

{% tabs %}
{% tab title="Example 1" %}
**Input:** "aab"

**Output:**

\[

\["aa", "b"],

\["a", "a", "b"]

]
{% endtab %}
{% endtabs %}

### **Solutions**

{% tabs %}
{% tab title="Solution 1" %}

```java
/**
 * Time complexity : 
 * Space complexity : 
 */

class Solution {
    public List<List<String>> partition(String s) {
        List<List<String>> resultList = new ArrayList();
        if(s == null || s.length() == 0) return resultList;
        helper(resultList, new ArrayList(), s, 0);
        return resultList;
    }
    
    private void helper(List<List<String>> resultList,
                        List<String> currList,
                        String s,
                        int start) {
        if(start == s.length()) {
            resultList.add(new ArrayList(currList));
            return;
        }
        
        for(int i = start; i < s.length(); i++) {
            if(isPalindrome(s, start, i)) {
                currList.add(s.substring(start, i+1));
                helper(resultList, currList, s, i+1);
                currList.remove(currList.size()-1);
            }
        }
    }
    
    private boolean isPalindrome(String s, int left, int right) {
        while(left < right) {
            if(s.charAt(left) != s.charAt(right)) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}
```

{% endtab %}
{% endtabs %}

### **Follow up**

*


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://code-snippets.hbamithkumara.com/leetcode/problems/101-200/palindrome-partitioning.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
