Let's assume you know what the problem is about. Now, the response of the function F can be viewed as the
sum of N different values, where each value represents the difference of ASCII value in that position. Formally,

F(S, X) = sum of |Si - Xi| for i = 1 to N.

Now, if we consider two strings Z = "zzzz...." (N times z) and A = "azzz..." (N-1 times z) and calculate the value of F for each of them and then subtract, we actually get the value of |S1 - X1|. Now, an observation is |c - 'a'| = c - 'a' and |c - 'z'| = 'z' - c, here c is an ASCII character since, 'a' ≤ S1 ≤'z'. Now if we query with these two strings, from their response we can correctly guess the character at position 1. That is,

F(S,Z) - F(S,A) = 'z' - 2*c + 'a'.

Now, following these steps we can solve for the substring from position [2, N] and [3, N] and so on. This way you will need 2*N times query of the format "? X". Now next observation is When you know the character at position 1, you can use this information to derive the response of F(S, "#zzzz....."), where # is S1. Then, the number of queries of the format "? X" can be reduced to N+1. Lastly, print the string as "! S".

Statistics

86% Solution Ratio
badassiumoxideEarliest, Apr '19
steinumFastest, 0.0s
mdshadeshLightest, 5.5 kB
aaman007Shortest, 341B
Toph uses cookies. By continuing you agree to our Cookie Policy.