Answer: Amazon | 10th October | Online Assessments

Answer · Posted Nov 2022

Solution for Question 2 This problem can be solved by binary searching on the answer. Let n be the length of the string and x be the number of operations performed. Make a prefix sum frequency array freq[n][26] from x+1 to n. Now, frequency from L to R for a letter j can be calculated by freq[R][j] - freq[L-1][j] in O(1). If the frequency of each letter in each range is less than 2, then the string would be a ...

The full answer & interview discussion are available to premium members.

Log in Create a free account