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 0s paired. Pairing two 0s 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

  1. Pairing happens from left to right. For each pairing, the second 0 will always be paired towards the first ( right to left )
  2. 0s generated by pairing can NOT be paired again
  3. ( void where not applicable: ) Don't modify the input array or you may fail to pass the tests
Algorithms
Arrays
Fundamentals
Functional Programming

Stats:

CreatedFeb 16, 2015
PublishedFeb 16, 2015
Warriors Trained4626
Total Skips127
Total Code Submissions7275
Total Times Completed2370
JavaScript Completions1250
Python Completions970
Ruby Completions99
COBOL Completions10
Haskell Completions64
C Completions61
λ Calculus Completions10
Go Completions22
Total Stars66
% of votes with a positive feedback rating91% of 390
Total "Very Satisfied" Votes330
Total "Somewhat Satisfied" Votes46
Total "Not Satisfied" Votes14
Ad
Contributors
  • Nianpeng Avatar
  • GiacomoSorbi Avatar
  • smile67 Avatar
  • JohanWiltink Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • Madjosz Avatar
  • rowcased Avatar
  • Gao-Jun Avatar
  • akar-0 Avatar
  • Kacarott Avatar
  • dfhwze Avatar
  • Just4FunCoder Avatar
  • BerkeliH Avatar
Ad