Created
January 27, 2017 13:38
-
-
Save vijayparashar12/66deccc0e63178fcf90e21db2c13c06f to your computer and use it in GitHub Desktop.
Solution of https://www.hackerrank.com/challenges/pairs
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
package hackerrank.pairs | |
/** | |
* Created by vparashar on 27/01/2017. | |
*/ | |
object PairWithDifference { | |
def main(args: Array[String]) { | |
val sc = new java.util.Scanner(System.in) | |
val n = sc.nextInt() | |
val k = sc.nextInt() | |
val dummy = "Dummy" | |
val map = scala.collection.mutable.HashMap.empty[Int, String] | |
for (i <- 0 to n - 1) { | |
map += ((sc.nextInt(), dummy)) | |
} | |
val pairs = map.keySet.foldLeft(0)((c, n) => if (map.contains(n + k)) c + 1 else c + 0) | |
print(pairs) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment