Company: Publicis Sapient_27sept
Difficulty: medium
Maximize Text Score Problem Description You are given three strings: text , prefixString , and suffixString . Your task is to find a non-empty substring of text that maximizes a value called textScore . The textScore of a substring is defined as: prefixScore : the length of the longest string P such that P is a suffix of prefixString and also a prefix of the substring. suffixScore : the length of the longest string S such that S is a prefix of suffixString and also a suffix of the substring. textScore = prefixScore + suffixScore . If multiple substrings achieve the maximum textScore , return the lexicographically smallest one. Examples Example 1: Input: text = "nothing", prefixString = "bruno", suffixString = "ingenious" Output: "nothing" Explanation: Consider the substring "nothing": "no" is a suffix of "bruno" and also a prefix of "nothing", so prefixScore = 2 . "ing" is a prefix of "ingenious" and also a suffix of "nothing", so suffixScore = 3 . textScore = 2 + 3 = 5 . This is the h