7 kyu
Pair Zeros
970 of 2,370Nianpeng
Description:
Task
For a given list of digits 0
to 9
, return a list with the same digits in the same order, but with all 0
s paired. Pairing two 0
s generates one 0
at the location of the first one.
Examples
input: [0, 1, 0, 2]
paired: ^-----^
-> [0, 1, 2]
kept: ^
input: [0, 1, 0, 0]
paired: ^-----^
-> [0, 1, 0]
kept: ^ ^
input: [1, 0, 7, 0, 1]
paired: ^-----^
-> [1, 0, 7, 1]
kept: ^
input: [0, 1, 7, 0, 2, 2, 0, 0, 1, 0]
paired: ^--------^ ^--^
-> [0, 1, 7, 2, 2, 0, 1, 0]
kept: ^ ^ ^
Notes
- Pairing happens from left to right. For each pairing, the second
0
will always be paired towards the first ( right to left ) 0
s generated by pairing can NOT be paired again- ( void where not applicable: ) Don't modify the input array or you may fail to pass the tests
Algorithms
Arrays
Fundamentals
Functional Programming
Similar Kata:
Stats:
Created | Feb 16, 2015 |
Published | Feb 16, 2015 |
Warriors Trained | 4626 |
Total Skips | 127 |
Total Code Submissions | 7275 |
Total Times Completed | 2370 |
JavaScript Completions | 1250 |
Python Completions | 970 |
Ruby Completions | 99 |
COBOL Completions | 10 |
Haskell Completions | 64 |
C Completions | 61 |
λ Calculus Completions | 10 |
Go Completions | 22 |
Total Stars | 66 |
% of votes with a positive feedback rating | 91% of 390 |
Total "Very Satisfied" Votes | 330 |
Total "Somewhat Satisfied" Votes | 46 |
Total "Not Satisfied" Votes | 14 |