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.
Okay, so I've seen a lot of complaining on this one, and I have worked out where the confusion lies. I too was confused, so I wrote out my assumptions and verified them against the problem until I saw where my misunderstanding lay.
The key point is that on first reading I thought the output should be: g(f(1)), g(f(2)), g(f(3)),...,g(f(n)), which would always be 1, 2, 3,...,n
However, the question is actually asking for: g(1), g(2), g(3),...,g(n)
So lets look at the case where the input is 5, 4, 3, 2, 1. To find g(1), we must find an f(x) where the return value is 1. In this case f(5) = 1, so g(1) = 5 (and therefore the first line of output should equal 5).
I hope this helps people understand what the problem is actually asking.
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 →
Okay, so I've seen a lot of complaining on this one, and I have worked out where the confusion lies. I too was confused, so I wrote out my assumptions and verified them against the problem until I saw where my misunderstanding lay.
The key point is that on first reading I thought the output should be: g(f(1)), g(f(2)), g(f(3)),...,g(f(n)), which would always be 1, 2, 3,...,n
However, the question is actually asking for: g(1), g(2), g(3),...,g(n)
So lets look at the case where the input is 5, 4, 3, 2, 1. To find g(1), we must find an f(x) where the return value is 1. In this case f(5) = 1, so g(1) = 5 (and therefore the first line of output should equal 5).
I hope this helps people understand what the problem is actually asking.