fword
BAN USER
Comments (7)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
you should update the key_dict[cum_sum] when cum_sum may appear more than twice,like array = [-1, -3, 4, 5, -2, -4, 6,-5]
the code should be
def get_sum(array):
cumsum_array = [0] + np.cumsum(array).tolist()
key_dict = {}
for index, cum_sum in enumerate(cumsum_array):
if cum_sum not in key_dict:
key_dict[cum_sum] = index
continue
print array[key_dict[cum_sum]: index]
key_dict[cum_sum] = index
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
ce we are comparing the string with its reverse, we will do at most K deletions and K insertions (to make them equal).
- fword August 30, 2013why insertions ??