Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
For brute force approach, why do we cut when there is a palindrome in the for lo...

Gary

May 11, 2022

For brute force approach, why do we cut when there is a palindrome in the for loop?

At top of the recursive function, we do NOT cut if it's a palindrome, so I'm confused by the different treatment here.

0

0

Comments
Comments
Design Gurus
Design Gurus3 years ago

At the top of the function, there is no cutting. If the string is a palindrome, we have found our answer.

Now we go down the function, as the string is not a palindrome.

The for loop tries to break the string to find if there are palindromes.

G
Gary 3 years ago

Got it. Thanks!

On this page