**Problem 1: Balanced string **

*“Everything should be balanced and your life is too. You could spend a lot of time for work but please save time for your family”,* said by a good father Toan. *“And a string should be as well, I think ToannaoT is better than my name”*, he went ahead. And he invented a “balanced string” that its characters are mirrored by its center. For example, **abcba** or **abccba** are balanced while **abcbc** and **abccbc** are not.

Give you a list of string, compute the sum of length of all balanced strings.

__Note:__ it’s also called “**palindrome**” which reads the same backward or forward.

**Sample input:**

1 2 3 4 |
abacnc abccba aca abcjks |

**Sample output:**

1 |
9 |

**Problem 2: Phone number**

Cuong has a locked iPhone and it always gives him a headache of contact and phone number mapping. For example, he saved his girlfriend’s number 0987654321 to his contact, but it always shows up 84-9876-54321 as it adds the country code automatically.

As a super programmer, he of course wants to fix this by a coding service to recognize each parts and join it himself. Do you want to solve it with Cuong?

Give you a list of phone numbers, each number in each line. A phone number has a format

PhoneNumber = [CountryCode][separator][LocalAreaCode][separator][Number]

With

**separator**is space or hyphen**CountryCode**,**LocalAreaCode**,**Number**only contain the digits.

Submit the result = [Sum_of_CountryCode] * [Sum_of_LocalAreaCode] * [Sum_of_Number]

**Sample input:**

1 2 3 |
1 877 2638277 91-011-23413627 8-43-4324 |

**Sample output:**

1 |
2425834826800 |

**Problem 3: Love letter**

Yesterday, The just found a love letter that his friend, Long, has writtent to his girldfriend. As a naughty boy, he want to meddle with this letter and change all the words to *“ballanced” (palindrome)* that Toan has invented. But to be safe, he should follow the rule and save his steps to make this letter recoveryable later.

- He can reduce the value of a letter but cannot increase. For example, he can change
**b**to**a**but cannot change**a**to**b**. - Once a letter has been changed to
**a**, it can no longer to be changed. - Each step, he can reduce 1 letter with 1 unit. For example, changing
**c**to**a**needs 2 steps.

So let find the minimum steps for him to change this letter to palindrome.

**Sample input**

1 2 3 4 |
abc abcba abcd cba |

**Sample output **

1 2 3 4 |
2 0 4 2 |

**Problem 4: Girl attracting law by Fibonacci approach**

After a long time in-door researched, Hung found a good approach to attract a girl and he named it*“Girl attracting law by Fibonacci approach”* that means the number of presents Hung gives to her is increased by Fibonacci sequence. But don’t stop, he extended to version 2 with some customisation by:

**T(n+2) = T(n+1) * T(n+1) + T(n)**

with **T(n)** is a number of presents at the n*th* dating.

Hung of course has a lot of money but wants to trust a girl, so he should give her 0 present at the first and 1 present at the second dating. And following his theory, 5 presents should be given in the 5th dating as explanation below:

1^{st} number = 0

2^{nd} number = 1

3^{rd} number = 1^{2} + 0 = 1

4^{th} number = 1^{2} + 1 = 2

^{5th} number = 2^{2} + 1 = 5

Hung said that he has meet her 13 times and today he wants to know how many present he should give. Could you help Hung?

*These problems are modified by some in Hackerrank*

138 total views, no views today