Page Menu
Home
desp's stash
Search
Configure Global Search
Log In
Files
F630462
Solution.java
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
936 B
Subscribers
None
Solution.java
View Options
public
class
Solution
{
public
static
int
solution
(
String
x
)
{
//assume entire cake can be fully split
for
(
int
i
=
x
.
length
()
-
1
;
i
>
0
;
i
--)
{
//max amount of slices will be the same even if we rotate the cake
int
t
=
countSlice
(
x
.
split
(
x
.
substring
(
i
),
-
1
));
//slice the cake and count the slices
if
(
t
!=
-
1
)
return
t
;
//smallest slice is always the most possible slice; return on first valid slice and stop
}
return
1
;
//if no slices are valid returns the lowest possible slice, aka the entire cake
}
public
static
int
countSlice
(
String
[]
split
)
{
for
(
String
s
:
split
)
{
//if not empty it means there are leftovers; Lambda would be enraged
if
(!
s
.
isEmpty
())
return
-
1
;
//stop and return invalid count
}
return
split
.
length
-
1
;
//valid slices; check count from split tokens
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 26, 1:02 PM (1 d, 2 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
27/8b/62b77fed6da17f7f91b7d1062a87
Attached To
rGFS Google foobar
Event Timeline
Log In to Comment