Suppose the total number of lines of code is a multiple of 3, i.e., of the form $$$3n$$$. Then the work can be evenly distributed among the three members — each writing exactly $$$n$$$ lines of code
If the number of lines is of the form $$$3n + 1$$$, then the optimal distribution would be: $$${n,\ n,\ n + 1}$$$
If the number of lines is of the form $$$3n + 2$$$, then the optimal distribution would be: $$${n,\ n + 1,\ n + 1}$$$
In both uneven cases above, the maximum number of lines any one member has to write is still $$${n + 1}$$$. Thus, for all three forms $$${3n,\ 3n + 1,\ 3n + 2}$$$, the answer is always: $$$\lceil \frac{x}{3} \rceil$$$ where $$$\lceil . \rceil$$$ is the ceiling value, and $$$x$$$ is the total number of lines of code.
Just stimulate the process: Iterate from index 0 to n-1, maintain a pointer j to the string "baton" initially at index 0. For each character in the input string, if it matches the current character pointed to in "baton", move the pointer forward. If the pointer reaches the end of "baton" j == 5, that means all characters 'b', 'a', 't', 'o', 'n' have been found in the same order one after another.



