MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / backtrack

Function backtrack

Recursive/PalindromePartitioning.js:14–28  ·  view source on GitHub ↗
(s, path, result)

Source from the content-addressed store, hash-verified

12}
13
14const backtrack = (s, path, result) => {
15 if (s.length === 0) {
16 result.push([...path])
17 return
18 }
19
20 for (let i = 0; i < s.length; i++) {
21 const prefix = s.substring(0, i + 1)
22 if (palindrome(prefix)) {
23 path.push(prefix)
24 backtrack(s.substring(i + 1), path, result)
25 path.pop()
26 }
27 }
28}
29
30export default partitionPalindrome

Callers 1

partitionPalindromeFunction · 0.85

Calls 3

palindromeFunction · 0.90
pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected