=begin two pointer: * left * right left moves -> right moves <- * they move towards each other until they meet. * if all characters are the same while they move towards each other, then we have a palindrome. l r |b|a|n|a|n|a| |b|a| |b|a|n| |b|a|n|a| |b|a|n|a|n| |b|a|n|a|n|a| |a|n| |a|n|a| |a|n|a|n| |a|n|a|n|a| |n|a| |n|a|n| |n|a|n|a| |a|n|a| recursive solution base case: * s is empty if s[0] == s[-1] run(s[1..-2]) end =end def assert_equal(x, y) return puts "PASS" if x == y puts "FAIL: expected #{x}, got #{y}" end class Solution def self.palindrome?(string) return false if string.nil? || string.empty? string == string.reverse end def self.run(string) max = "" for l in (0..string.size) for r in (l+1..string.size) candidate = string[l..r] if palindrome?(candidate) && candidate.size > max.size max = candidate end end end max end end assert_equal 'anana', Solution.run('banana') assert_equal 'illi', Solution.run('million') assert_equal 'racecar', Solution.run('tracecars') assert_equal 'tacocat', Solution.run('loltacocatmom')