My intent is not to provide an answer per se, rather it’s to provide insight into the way I think and to foster discussion. Copy & paste at your own risk.
This is one of 3 tests that I recently took in applying for a developer position. Due to copyright restrictions I cannot post the problem here verbatim. I’ve substituted certain values and names. I can give you the gist (both🙂 here:
- the input string P can have a length of 0 – 50000
- the input string P will only consist of the characters X, Y and/or Z
Keep in mind that this is my interpretation of the task at hand. While it’s unfortunate that I can’t recreate the test verbatim here, I can say it was very explicit, but did leave room for interpretation. Without further ado…
Write a function
..such that, if any transformation applies, pick one at random, transform the string, and continue the process until no transformations are applicable. Now where there is some room for interpretation is in the transformation rules. An example of a transformation rule looks like this:
substitute some occurrences of “XY” with “XX”
As you can see, the word “some” could be interpreted differently. Rather than overthink that part of the test, I assumed they meant to apply the transformation to any & all occurrences. I think the coding difference is rather trivial at this point.
- XY -> XX
- YX -> XX
- YZ -> ZZ
- ZY -> ZZ
- XX -> X
- ZZ -> Z