We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
They way I was originally thinking of this problem was if your input was 1 2 3.
f(1) would be 1, f(2) would be 2, f(3) would be 3. Then performing the inverse of the function would give you g(1) = 1, g(2) = 2.. etc.
Seeing the discussions on here saying g(3) = 1, g(2) = 2, g(1) = 3 makes sense I get that and can follow that.
But, the final test case makes no sense.
The input is as followed:
2 4 6 8 10 12 14 16 18 20 19 17 15 13 11 9 7 5 3 1.
Following the logic above g(20) should be equal to 2, g(19) should = 4, etc...
Why the output for testcase 3 is 20, 1, 19, 2, 18, 3, 17 etc... does not make any sense.
If this testcase was to be consistent with the previous testcases, g(10) would be equal to 20 and g(20) would be equal to 2, but it isn't.
Can anyone enlighten me on what is going on?
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Security Function Inverses
You are viewing a single comment's thread. Return to all comments →
They way I was originally thinking of this problem was if your input was 1 2 3. f(1) would be 1, f(2) would be 2, f(3) would be 3. Then performing the inverse of the function would give you g(1) = 1, g(2) = 2.. etc.
Seeing the discussions on here saying g(3) = 1, g(2) = 2, g(1) = 3 makes sense I get that and can follow that.
But, the final test case makes no sense.
The input is as followed: 2 4 6 8 10 12 14 16 18 20 19 17 15 13 11 9 7 5 3 1.
Following the logic above g(20) should be equal to 2, g(19) should = 4, etc...
Why the output for testcase 3 is 20, 1, 19, 2, 18, 3, 17 etc... does not make any sense.
If this testcase was to be consistent with the previous testcases, g(10) would be equal to 20 and g(20) would be equal to 2, but it isn't.
Can anyone enlighten me on what is going on?