shashank shandilya
BAN USERRuby Solution to the above problem
def flipZero( arr = [], m )
left = 0
right = 0
max = -1
zeroc = 0
lefti = 0
righti = 0
start_zero_loc = 0
while right < arr.length
#puts "right #{right} :: zeroc #{zeroc} :: left #{left} :: max #{max} :: start_zero_loc #{start_zero_loc}"
if zeroc <= m
right += 1
if arr[ right ] == 0 then
zeroc += 1
if zeroc == 1 then
start_zero_loc = right
end
end
else
if arr[ right ] == 0 then
zeroc -= 1
if zeroc == 1 then
start_zero_loc = right
end
left = start_zero_loc
end
left += 1
end
if ( right - left ) > max
max = ( right - left )
lefti = left
righti = right
end
end
p [max, lefti, righti]
end
flipZero([1, 1, 0, 1, 1, 0, 0, 1, 1, 1], 2)
RepKinsleyJames, Network Engineer at Accenture
I graduated from College with a master’s degree in arthrogryposis. After graduation I am working as a manager in ...
Reprchierusel, Applications Developer at Allegient
I am a Real-time captioner in the USA . Real-time captioning can be used for programs that do not have written ...
RepRichardWParks, Accountant at ADP
yeah, Nicely explained but faced few difficulties while implementing it.
- shashank shandilya October 24, 2014