left
and right
, pointing to the start and end of the string respectively.temp1
and temp2
, to store the characters being compared.count
to keep track of the number of valid decompositions.left
is less than right
:
a. Append the character at left
to temp1
and the character at right
to temp2
.
b. If temp1
is equal to the reverse of temp2
, a valid decomposition is found:
i. Increment count
by 2.
ii. Reset temp1
and temp2
to empty strings.
iii. Move left
and right
pointers inward.
c. If no match is found, continue moving the pointers inward.left
equals right
and temp1
is empty, increment count
by 1.temp1
is not empty, increment count
by 1.count
.