Skip to content

Instantly share code, notes, and snippets.

@vijayparashar12
Created January 27, 2017 13:38
Show Gist options
  • Save vijayparashar12/66deccc0e63178fcf90e21db2c13c06f to your computer and use it in GitHub Desktop.
Save vijayparashar12/66deccc0e63178fcf90e21db2c13c06f to your computer and use it in GitHub Desktop.
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