#K49697. Shortest Subsequence Length for 'code'
Shortest Subsequence Length for 'code'
Shortest Subsequence Length for 'code'
Given a string S
, determine whether it contains the subsequence code (i.e. the characters 'c', 'o', 'd', 'e' in that exact order). Note that the characters forming the subsequence do not need to be contiguous, but they must appear in the given order.
If such a subsequence exists, output the length of the target subsequence, which is \(4\); otherwise, output \(-1\).
Example:
- For S = "codex" the answer is 4 because the subsequence "code" can be found.
- For S = "hello" the answer is -1 since the required subsequence does not exist.
inputFormat
The first line of input contains a single integer \(T\) (the number of test cases). Each of the following \(T\) lines contains a single non-empty string \(S\).
Input is read from standard input (stdin).
outputFormat
For each test case, print a single line containing the answer: \(4\) if the string contains the subsequence code
in order, and \(-1\) otherwise.
Output should be written to standard output (stdout).
## sample3
codex
hello
ocde
4
-1
-1
</p>