I am designing a game; Here I need to find max score for that I need to find max moves player can make.
for example -
playerA-value =
abccdI need to find the substring saybcin playerA-valueNow I deleted it. So playerA-value = acd
algorithm checks for
bcand it not found, so max move = 1.
for example -
playerA-value =
aeerrbI need to find the substring sayerin playerA-valueNow I deleted it. So playerA-value =
aerbalgorithm checks for
erand it found, above steps repeats, finally max move = 2.
to maximize the score, I can delete it either from the front end of the string or rear end, or combination of both(like first few time front, later check for the back side.
Is there any formula in combination or permutation to find this?
I wrote the following Java code to output the maximum number of removals of a substring from a string.
The code uses
replaceFirstwithin a while loop, until it can no longer be applied. The code counts the number of times the while loop executes, and this is the integer output.I ran the test code, and all nine test cases gave the expected output.