At The End
All the students are suffering from a problem called "Lack of money :( ". Now one day Santa has found a bridge consisting of N checkpoints. Each checkpoint have been assigned a character from 'a' - 'z' (lower case alphabets). He was there at the starting of the bridge and the money Bag was there at the end. Any how he wants to reach at the end of the bridge. At each checkpoint a guard was there so he has to pay them to move forward. But the payment scheme was a little different than the normal. From a checkpoint Santa can only move to the next checkpoint or to any checkpoint with the same character assigned(only in forward direction). The cost that the guard will take is the absolute difference of their ascii values. So you have to help Santa in order to find the minimum amount of money, he should start with in order to reach at the end.
The first line contains an integer T denoting the number of test cases. The description of T test cases follows.
A string is given in a new line of length N.
- For each test case, output a single line containing the minimum amount of money which Santa needs to have at the beginning.
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 100000
Input: 1 abcdefac Output: 2
Example case 1.Assuming the string to be 1 indexed, From 1st index Santa jumped to 7th index and the cost required is 0 and then from 7th index to the last with cost abs(99-97) = 2
Total cost required = 0 +2 = 2
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions