7 kyu
Simple Fun #124: Lamps
269 of 604myjinxin2015
Description:
Task
N lamps are placed in a line, some are switched on and some are off. What is the smallest number of lamps that need to be switched so that on and off lamps will alternate with each other?
You are given an array a
of zeros and ones - 1
mean switched-on lamp and 0
means switched-off.
Your task is to find the smallest number of lamps that need to be switched.
Example
For a = [1, 0, 0, 1, 1, 1, 0]
, the result should be 3
.
a --> 1 0 0 1 1 1 0 swith --> 0 1 0 became--> 0 1 0 1 0 1 0
Input/Output
[input]
integer arraya
array of zeros and ones - initial lamp setup, 1 mean switched-on lamp and 0 means switched-off.
2 < a.length <= 1000
[output]
an integer
minimum number of switches.
Puzzles
Similar Kata:
Stats:
Created | Feb 15, 2017 |
Published | Feb 15, 2017 |
Warriors Trained | 1205 |
Total Skips | 31 |
Total Code Submissions | 2274 |
Total Times Completed | 604 |
JavaScript Completions | 198 |
C# Completions | 82 |
Python Completions | 269 |
PHP Completions | 71 |
Ruby Completions | 41 |
Total Stars | 20 |
% of votes with a positive feedback rating | 94% of 175 |
Total "Very Satisfied" Votes | 158 |
Total "Somewhat Satisfied" Votes | 13 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 6 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |