# Security Bijective Functions

# Security Bijective Functions

Bane19 + 3 comments I do not understand the problem. please elaborate.

Crownie + 2 comments I second this.

Its a bit blurry for me too.

You do know what set X is but I have no idea how to figure out what set Y is.**edit:**Is the array you receive as input set Y?

Or did I misunderstand that?jdeyrup + 2 comments You are being asked to answer whether two sets meets a definition (bijection). Your first set are your x values, these are your inputs to the function. So say the function is f(x)= x^2, the first set is the values of x say (1,2,3). The second set is your ouput. So in this case (1^2, 2^2, 3^2) = (1,4,9). Again the two sets are (1,2,3) and (1,4,9). Now the question asks how do you know if this a bijection. A bijection means that each value x corresponds to a unique value y and each value y corresponds to a unique value x. So 1 -> 1, 2 -> 4, 3->9. So this set is a bijection. Sets that wouldn't be bijections are (1,2,3,5) -> (1,4,9) x value 5 does not correspond to any value y, (1,2,3) -> (1,4,9,16) y value 16 does not correspond to any x value, (1,1,3) -> (4,2,3) 1 value x corresponds to multiple y values, (4,2,3) -> (1,1,3) 1 value corresponds to multiple x values.

Blater + 2 comments This is a pretty abstract question which tests that you're already familiar with the mathematical concept of bijective functions (thats "function" in the mathematical sense, not the programming sense).

My translation of it was : if the all the numbers in the input array are unique return YES

else return NO.m2gleason + 0 comments thanks man. appreciate it.

khuongduybui + 0 comments and the number of numbers in the input array matches the first input as well.

SAvila120692 + 0 comments Thank you.

SimeonD + 0 comments bijective = function is ONTO and ONE TO ONE,

.

array index is the x in f(x) = y

the input is y in the f(x) = y

.

start by storing the inputs into an array or vector, ONTO means every input has an array index, which in this case has to be true if stored properly

.

so all you gota check if its ONE TO ONE, the only way this would fail is if you have a duplicating number ( same number in more than 1 index )

.

simply run through your array or vector and check for any repeating numbers and if you dont have any "YES" else "NO"

PRASHANTB1984 + 1 comment Do take a look at successful submissions from the leaderboard about ideas for a working approach!

cliff_free + 0 comments Aside from some of those "successful" submissions being incorrect (test data sets weren't elaborate enough to find some common errors), this is NOT the way to learn.

babuamar455 + 0 comments # include

# include

# include

# include

int main() { int a,b=0,c[100]; scanf("%d",&a); for(int i=0;i=0;j--){ if(c[i]==c[j]){ b++; } } } if(b>0){ printf("NO"); } else printf("YES");

`return 0;`

}

maikdevelops + 0 comments Python 3

#!/usr/bin/python3 n = input() # Not really that useful to us. inputs = input().strip().split() # Create a list with the numbers if len(set(inputs)) == len(inputs): ''' set() returns a list with only the unique entries in the list. so if the length of unique items == the length of the list itself then it contains no duplicates, otherwise it does contain duplicates. ''' print("YES") else: print("NO")

electrogeek + 1 comment The

*sample input*and the*explanation*at the end are contrary to test case 1.The function is not

`f(x) = x`

tilper + 1 comment How so?

electrogeek + 1 comment The test case 1 has input from 1 to 20 in random order, however the explanation says:

"The second line contains n space separated integers, the values of f(1), f(2), f(3), ..., f(n) respectively."

If function is

f(x) = x

then input should not be in random order, or rather the problem should not say that the function isf(x) = x

hackerrank152 + 0 comments I find the task not particularly informative or well posed. Basically, you're required to determine whether the given list of N numbers is a permutation of 1..N, but that's not the way the question is phrased. Instead, it is clothed in some unmotivated definitions (which, incidentally, also have very little to do with Security).

scriba + 3 comments Python3 one-liner:

print ('YES') if int(input()) == len(set(map(int, input().split(' ')))) else print('NO')

polmki99 + 0 comments [deleted]ethan_sec + 1 comment But if the input would be:

3 1 2 4

Then the answer should be "NO" because the image isn't {1..3} but your code would answer "YES"

quapka + 1 comment Hmm, that depends, the function in the assignement is said to be, f:X -> X. That is the domain and codomain are the same sets. Now, in your input n=3 that is X = {1, 2, 3}. So, by the definition you should only use those values for the outputs (4 is forbidden). From the definition in the assignement f is basically a permutation of {1, 2, ... , n} for some positive n.

ethan_sec + 0 comments Right! Which is why I think the solutions posted in the discussion are wrong, and the solution I submitted checks the range as well (Python 2):

print "YES" if range(1,input()+1)==sorted(list(set(map(int,raw_input().split())))) else "NO"

noxious_av + 0 comments By the way we're taking input, the function is always onto, we just have to check for one-one mapping.

Scent_Leader + 0 comments My guess...

#!/bin/usr/ruby # Enter your code here. Read input from STDIN. Print output to STDOUT n = gets.strip.to_i fVal = gets.strip.split(' ') print fVal.uniq.length == n ? "YES" : "NO"

alexa_rockwell + 0 comments For some reason, my submissions doesn't pass the first test, but it passes for the other two. What could cause that?

NileshHindoliya + 2 comments My code doesn't showing anything here but when I run the code on my machine it runs fine. I don't understand what's the problem.

akshay_b130129csAsked to answer + 1 comment which language r u using??

NileshHindoliya + 0 comments Java 8

AFriendlyRobot + 2 comments In order to test my code on the website for this problem, I had to tick the "Test against custom input" box and create my own sample input.

For some reason I think this problem doesn't have the sample input set up to run against your code (for testing) by default. Hopefully that helps.

akshay_b130129cs + 0 comments For some problems there are no sample inputs!!

NileshHindoliya + 0 comments Yes this thing works. There is no Sample Inputs It only works for Custom Test Cases. @AFriendlyRobot @akshay_b130129cs

KnightOfNi + 2 comments I have submitted an answer to this question, but when run against test case number 3 (x = 5, y = {2, 3, 4, 5, 2}), it claims my solution returns "NO." I find this odd, because when I copy and paste my solution and run it on my computer, test case number 3 returns "YES."

evincentAsked to answer + 0 comments I tried your solution with the test case you gave me (x=5, y={2,3,4,5,2} and your answer is YES while NO is expected

You did not test correctly, it is not enough to check that each data in y is a number. You should read again the description of a bijective function Come back to me if you need more hints

ChandikaAsked to answer + 0 comments I think you understand the question incorrectly. x must be in y at least one time.

try this,i used python

isBijective = "YES" For i = 1 To y.length If y.count(i)>1 Then isBijective = "NO" End If Next Display isBijective

Sort 63 Discussions, By:

Please Login in order to post a comment