DCP-455: String Problem Back to All Problems

Easy Math > Basic Math

You are given a string **S** with **N** letters ( UPPER & lower case, Case-sensitive ). S = { S(1) , S(2) , .... S(N) } . In one move you can select any index **i** and update **S(i)** with **S(i+1) or S(i-1)**. But you can update **S(1)** only with **S(2)**.<br> And, you can update **S(N)** only with **S(N-1)**. What is the minimum number of moves need to **S** contain same letters? Input: ------ Input starts with an integer **T (1<=T=100)**, denoting the number of test cases. Each case contains **S** and **N**. N>1 and N<=10000. Output: ------- For each case of input, output minimum number of moves need to **S** contain same letters. Sample Input ------------ 2 AKA 3 ABC 3 Sample Output ------------- 1 2 ---------- *Test case 2* : **ABC -> AAC -> AAA**

Problem Limits

 Language Time Limit (seconds) C 1.00 C++ 1.00 C++14 1.00 C# 2.00 Go 2.00 Java 2.00 JavaScript 2.00 Objective-C 2.00 Perl 2.00 PHP 2.00 Python 2.00 Python3 2.00 Ruby 2.00 VB.Net 2.00

75/130

Solve/Submission

Ranking

# User Language Timing
01 ssavi Cpp 0.00s
02 FariD Cpp14 0.00s
03 ss1230 Cpp14 0.00s
04 MazedRupok Cpp 0.01s
05 emrul Cpp 0.01s
06 feodorv C 0.01s
07 _GhOstMan_ Cpp 0.01s
08 souravahmed C 0.01s
09 st3inum Cpp 0.03s
10 unknown420 Cpp 0.03s
11 Abu_Bakar Cpp 0.03s
13 int_elligent Cpp 0.04s
14 Silent_Warrior Cpp 0.04s
15 nafiz0080 Cpp 0.04s
16 tariqiitju Cpp 0.04s
17 simantaturja Cpp 0.04s
18 JubayerSohel Cpp 0.04s
19 bug_is_everywhere Cpp 0.04s
20 hmsayem Cpp 0.04s
21 Riaz_BSMRSTU Cpp 0.04s
22 Superstorm Cpp14 0.05s
23 anik_JU Cpp 0.08s
24 mbstu_alamin16 Cpp 0.08s
25 subhashis_cse Cpp 0.09s
26 by_default Cpp 0.21s
27 kissu_pari_na Cpp 0.23s
28 joty_ict Cpp 0.24s
29 motaleb_ICT Cpp 0.25s
30 SakibAlamin Cpp 0.25s
31 Ruhul1975 Cpp 0.26s
32 Pure_Protea Cpp14 0.28s
33 Durbin Cpp14 0.28s
34 DynamicOvi Cpp 0.29s
35 indroneel Cpp 0.42s
36 mepromee Cpp 0.45s
37 rayhan50001 Cpp 0.45s
38 arnob_roy Cpp 0.45s