Hi Guys,
I’ve been trying to solve the Bulbs and Wires problem from the September Cook-Off challenge. I was initially getting Run Time Error (NZEC), after trying exception handling I’m not getting the “wrong answer” error please help.
Code link:
https://www.codechef.com/viewsolution/38985807
Line: Logic I used:
10-25 sum() which returns the sum of elements of a list.
27-35 count() which counts no of chars in the string
48-62 loops through the given string and counts no. of
0’s that are in sequence.
63-66 checks for ‘10’ at the end, as this is a corner case
not covered by the above mentioned for loop
67-78 adds elements to cut2 (a list containing 0’s that
require 2 cuts) and cut1(a list containing 0’s that
require 1 cut)
80-83 if k = 0 prints 0
84-105 if k=1 removes the max element from cut1 list
prints
the sum of cut2 and remaining element in cut1
106-134 if k>=2 it keeps removing elements until k<=0 and
prints the sum of elements present in cut1 and
cut2.
Overall Logic:
- from the given string, I want to find the number of 0’s occurring sequentially and store it in cut2.
- From cut2, I want to check whether the string is starting or ending from 0, and adding the number of such 0’s in sequence to cut1 i.e no. of zeroes that need 1 cut to get isolated.
- As per k value, keep removing the maxing number in either of the lists so that the minimum number of bulbs needs to be disconnected.
P.S.: I’m an amateur coder, I’d be grateful if you provide me any suggestions to improve my coding skills.