Find Longest valid Parentheses Length [ Google ]

Problem: Given a string consisting of opening and closing parenthesis, find length of the longest valid parenthesis sub string.[Courtesy: geeksforgeeks] Problem Link Solution: The problem can be solved with DP approach . And also as counting the left and right parenthesis from left to right.If the left parenthesis count is less than the right parenthesis

Maximum Boolean Parenthesization String [ Microsoft, Amazon]

Problem: Count the maximum number of ways we can parenthesize of a given boolean expression so that the value of expression evaluates to true or false as asked. Boolean expression will be given with following symbols. Symbols     ‘T’ —> true     ‘F’ —> false And the Operators     &   —> boolean AND     |   —>

Find the longest palindrome of a String [Amazon,Microsoft]

Problem: Find the length and/or string of the longest palindrome of a string. The problem appeared as an Interview question in Amazon, Microsoft. Solution: One important property of a palindrome is if we remove the first and last characters of it , it would be another palindrome. So A string S[a..b] will be a palindrome

10166

 

10039

 

11022

This is a dp problem where kmp algorithm(specially prefix function)  is used to solve the problem. If a string is multiple of a repeated string then the difference between the string length and last index of the prefix table indicates the minimal length of the repeated string. A brief and nice discussion is available here .

13032

 

11008

 

11003