Блог пользователя algoprince

Автор algoprince, история, 13 месяцев назад, По-английски

You are given an array of strings. You can merge two strings, arr[i] and arr[j], only if, i < j and the last letter of arr[i] == first letter of arr[j] Eg, you have two strings -> “123” and “389” -> after merging it becomes “123389” You can keep merging strings like this, but the ‘final’ string you form must be such that the first letter of the string should be the same as the last letter. Eg, after merging several strings, the ‘final’ string becomes -> “123389…………1 Print the max length of the ‘final’ string that can be formed in this way. Test case — 1: Array of strings = [“14”, “123”, “323”, “321”, “421”, “535”] Possible ‘final’ strings -> “323”, “535”, “14421”, “123323321”, “123321” Ans = 9 (which is the length of “123323321”) Test case – 2: Array of strings = [“14”, “15”, “89”, “22”] Possible ‘final’ strings -> “22” Ans = 2 (which is the length+ of “22”) 1 <= ai <=1e9. 1 <=N<= 1e5

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится