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.
defseparateNumbers(s):is_beautiful=Falsecurr=s[0]first=currnext_start_idx=len(curr)whilelen(curr)<=len(s)// 2 and not is_beautiful:next_assumpted=str(int(curr)+1)next_actual=s[next_start_idx:next_start_idx+len(next_assumpted)]ifnext_actual==next_assumpted:ifnext_start_idx+len(next_actual)==len(s):is_beautiful=Trueelse:curr=next_actualnext_start_idx+=len(curr)else:curr=s[:len(curr)+1]first=currnext_start_idx=len(curr)print(s,f'YES{first}'ifis_beautifulelse'NO')
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Separate the Numbers
You are viewing a single comment's thread. Return to all comments →
Python