Created
January 5, 2021 12:04
-
-
Save mytja/cb005c1aba6423801621b82f0d5eebe1 to your computer and use it in GitHub Desktop.
Solution for The Cake Is Not A Lie (Google Foobar)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def substring_check(length, sub_str): | |
for i in range(0, length-1): | |
if(sub_str[i] == sub_str[i+1]): | |
if(i == length-2): | |
return length | |
else: | |
continue | |
else: | |
return 1 | |
def solution(s): | |
parts = 1 #Initially, Let's just assume that cake can be divided into just one piece | |
for i in range(1, len(s)): | |
sub_str = [] | |
if(len(s) % i == 0): | |
for j in range(0, len(s), i): | |
sub_str.append(s[j:j+i]) | |
parts = substring_check(len(sub_str), sub_str) | |
if(parts != 1): | |
return parts | |
return parts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment