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.
Here is my solution in Scala. I am coming from Python, so try and point out where I can make something more idiomatic to Scala.
objectSolution{defmain(args:Array[String]){vallstSize=readInt// Create an initial Map objectvaroriginalDict=readLine.split(" ").map(_.toInt).grouped(2).map(e=>(e.head,e.reverse.head)).toMapfor(i<-2tolstSize){// Continually modify the original map object based on intersect of keysvarupdateDict=readLine.split(" ").map(_.toInt).grouped(2).map(e=>(e.head,e.reverse.head)).toMapvarkeys=originalDict.keySet&updateDict.keySetoriginalDict=keys.map(k=>k->math.min(originalDict(k),updateDict(k))).toMap}// The output has to be sorted by keysvaloutput=originalDict.toList.sortBy(_._1).flatten{case(a,b)=>List(a,b)}.mkString(" ")println(output)}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lists and GCD
You are viewing a single comment's thread. Return to all comments →
Here is my solution in Scala. I am coming from Python, so try and point out where I can make something more idiomatic to Scala.