Created
August 9, 2018 05:26
-
-
Save ebongzzang/601d6755059568eb4e5689ecff4a6b87 to your computer and use it in GitHub Desktop.
climbing the leaderboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Solution { | |
// Complete the climbingLeaderboard function below. | |
def climbingLeaderboard(scores: Array[Int], alice: Array[Int]) = { | |
val score2 = scores.distinct | |
val length = score2.length-1 | |
var j = length | |
for(i:Int <- alice) yield { | |
val cond = score2.search[Int](i)(Ordering[Int].reverse) match { | |
case Found(foundIndex) => foundIndex | |
case _ => -1 | |
} | |
if(cond != -1) { | |
cond +1 | |
} else if(score2(length) > i) { | |
length +2 | |
} else if (score2(0) < i) { | |
1 | |
} else { | |
while (score2(j)<i) { | |
j -=1 | |
} | |
j+2 | |
} | |
} | |
} | |
def main(args: Array[String]) { | |
val stdin = scala.io.StdIn | |
val printWriter = new PrintWriter(sys.env("OUTPUT_PATH")) | |
val scoresCount = stdin.readLine.trim.toInt | |
val scores = stdin.readLine.split(" ").map(_.trim.toInt) | |
val aliceCount = stdin.readLine.trim.toInt | |
val alice = stdin.readLine.split(" ").map(_.trim.toInt) | |
val result = climbingLeaderboard(scores, alice) | |
printWriter.println(result.mkString("\n")) | |
printWriter.close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment