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.
Scala:
given x -> f(x), if x1 = x2 then f(x1) = f(x2), if f(x1) != f(x2), it is not a function.
This is the code in scala:
importscala.io.StdInobjectSolution{defmain(args:Array[String]){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution*/varcount_tests=StdIn.readIntfor(j<-List.range(0,count_tests)){varinput=StdIn.readIntvarrelations=collection.mutable.Map[Int,Int]()varresult=truefor(i<-List.range(0,input)){vartest_arr=StdIn.readLine()vartest1=test_arr.split(" ")(0).toIntvartest2=test_arr.split(" ")(1).toIntif(!relations.contains(test1))relations=relations+(test1->test2)else{if(relations(test1)!=test2)result=false}}if(result)println("YES")elseprintln("NO")}}}
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 →
Scala: given x -> f(x), if x1 = x2 then f(x1) = f(x2), if f(x1) != f(x2), it is not a function. This is the code in scala: