Is this approach correct for solving problem ENCODE04?

Problem link : ENCODE04

If the string has odd length, output NO, else if number of testers (T) in the first half of the string == the number of developers (D) in the second half and T > 0, output YES.

No, it’s not so easy, for example input TTDTDD is valid.

Those pairs are valid:

TTDTDD

TTDTDD

TTDTDD

No, that’s not true. Input DTTD is not valid.

UPD This input will break also some heuristics like you just answered to betlista’s answer - TDDTTTTDDD

1 Like

@betlista According to my logic also, TTDTDD is valid. tsUQhV - Online C++0x Compiler & Debugging Tool - Ideone.com

Ok, my test case is not valid for you. But you didn’t described properly your algorithm too…

for DTTD |T| in first half = |D| in second, but you print “No”…

Your algorithm print “No” for TTDDTTDD which is wrong…

1 Like

@betlista I forgot to add that I had added one more condition in my code : the number of testers in the first half (T) > number of developers in the second half of the string.