Skip to content

Instantly share code, notes, and snippets.

@jackliusr
Last active August 29, 2015 14:04
Show Gist options
  • Save jackliusr/e799de9c891301647581 to your computer and use it in GitHub Desktop.
Save jackliusr/e799de9c891301647581 to your computer and use it in GitHub Desktop.
Hackerrank Maximizing XOR in Scala , several test cases are terminated due to timeout. Possible the number is overflowed.
object Solution {
def maxXor(l: Int, r: Int): Int = {
var maxV :Int = 0;
for(i <- l to r; j <- i to r)
maxV = maxV.max( i ^ j)
maxV
}
def main(args: Array[String]) {
var _l:Int = Console.readInt
var _r:Int = Console.readInt
val res = maxXor(_l, _r)
println(res)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment