We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
deffind(arr,st,end,sum_till,cut,su):cf=find_crtcl_index(arr,sum_till,cut,st,end,su/2)ifcf!=None:left=find(arr,st,cf,sum_till,cut,su/2)right=find(arr,cf+1,end,sum_till,cut+(su/2),su/2)return1+max(left,right)else:return0deffind_crtcl_index(arr,sum_till,cut,st,end,fulfil):ifst==end:returnans=Nonewhilest<=end:mid=(st+end)//2val=sum_till[mid]-cutifval==fulfil:ans=midifval<fulfil:st=mid+1else:end=mid-1returnansdefarraySplitting(arr):# Write your code heresum_till=[]pr=0foriinarr:pr+=isum_till.append(pr)ifset(arr)=={0}:returnlen(arr)-1returnfind(arr,0,len(arr)-1,sum_till,0,sum_till[-1])
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Nikita and the Game
You are viewing a single comment's thread. Return to all comments →
Simple python nlogn solution: