- Practice algorithmic problem solving
Given an input array and a target value k
, return all distinct pairs of
consecutive numbers that add up to k
. A pair is distinct if no other pair
contains the same numbers.
The order of the pairs and order of the values in each pair does not matter,
e.g. we consider [[2, 8], [7, 3]]
to be the same as [[3, 7], [8, 2]]
.
Input: [0, 1, 1, 2, 0, 1, 1], 2
Output: [[1, 1], [2, 0]]
Input: [3, 4, 2, 1, 5, 2, 8, 2], 10
Output: [[2, 8]]
Use the language of your choosing. We've included starter files for some languages where you can pseudocode, explain your solution and code.
- Rewrite the problem in your own words
- Validate that you understand the problem
- Write your own test cases
- Pseudocode
- Code!
And remember, don't run our tests until you've passed your own!
cd
into the ruby folderruby <filename>.rb
cd
into the javascript foldernode <filename>.js
cd
into the ruby folderbundle install
rspec
cd
into the javascript foldernpm i
npm test