Amazon OA Question
Anonymous User
188

Anna starts by coming up with a word that consists of only 2 types of characters: 'a' and 'n'. She then picks out some characters from it to form a desired sub-string, and compresses it.

Anna calls a sub-string desired if, after compression, it becomes a palindrome. Compression is a mechanism in which Anna merges all consecutive characters of the desired sub-string. The characters she's allowed to merge must be equal to each other.

The goal of the game is to find how many desired sub-strings Anna can find in a made up word. To be precise, Anna has to find:

  1. Number of desired sub-strings of even length that can be compressed to give a palindrome

  2. Number of desired sub-strings of odd length that can be compressed to give a palindrome

Return a vector of size 2 where index 0 is the number of desired substrings of even length and index 1 is the numbner of desired substrings of odd length.

n = length of string = 100000

Comments (1)