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.
In case it is useful for someone, in the context of this challenge, a valid function is that which for a given input, ALWAYS gives the same output.
VALID Function
Given a function f() that functions as:
f(1)=1f(2)=2f(3)=3f(2)=2f(4)=1000
It is considered VALID, as outputs are always in a 1:1 relation with inputs, even although we don't know the exact way the relationship (function) works (i.e. we got no idea how f(4) gives 1000).
INVALID Function
A function g() which functions as follows:
g(1)=1g(2)=333g(3)=89g(2)=777g(4)=1000
The above function g, is NOT VALID, since, for input 2, we get two different results, first 333, then later we get 777.
NOTE : It is worth noting that multiple inputs may give the same output:
f(1)=99f(2)=99f(3)=99
Would still be a valid function.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Functions or Not?
You are viewing a single comment's thread. Return to all comments →
Might be helpful to know ...
In case it is useful for someone, in the context of this challenge, a valid function is that which for a given input, ALWAYS gives the same output.
VALID Function
Given a
function f()
that functions as:It is considered VALID, as outputs are always in a 1:1 relation with inputs, even although we don't know the exact way the relationship (function) works (i.e. we got no idea how f(4) gives 1000).
INVALID Function
A
function g()
which functions as follows:The above function g, is NOT VALID, since, for input 2, we get two different results, first 333, then later we get 777.
NOTE : It is worth noting that multiple inputs may give the same output:
Would still be a valid function.