Created
December 19, 2013 16:04
-
-
Save dscataglini/8041664 to your computer and use it in GitHub Desktop.
Finding Pairs
Given N integers, count the total pairs of integers that have a difference of K.
Sample Input #00:
k = 2 n = 1 5 3 4 2 Sample Output #00:
3 Sample Input #01:
k = 1
n = 363374326 364147530 61825163 1073065718 1281246024 1399469912 428047635 491595254 879792181 1069262793 Sample Output #01:
0
This file contains hidden or 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
require 'test/unit' | |
# Head ends here | |
def pairs( a,k) | |
#a is an array containing numbers and k is the difference. | |
end | |
class PairTest < Test::Unit::TestCase | |
def test_small_occurances | |
assert_equal 3, pairs([1, 5, 3, 4, 2], 2) | |
end | |
def test_for_zero_occurances | |
assert_equal 0, pairs([363374326, 364147530, 61825163, 1073065718, 1281246024, 1399469912, 428047635, 491595254, 879792181, 1069262793], 1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
javascript