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.
- Prepare
- Mathematics
- Fundamentals
- Bus Station
- Discussions
Bus Station
Bus Station
Sort by
recency
|
58 Discussions
|
Please Login in order to post a comment
But Solution is almost correct for all but only two, anyone can recode my code
An efficient java solution.
Uses the cumalative sum of each group and checks if it can be divided equally into the total sum before checking if valid.
a simple python3 solution
idea: you dont need to get all divisors of the total sum. you can compute the accumulate sums, and check only these divisors showing up there.
look at the following the example
arr = [1, 2, 1, 1, 1, 2, 1, 3]
accumulate_sum = [1, 3, 4, 5, 6, 8, 9, 12]
for example, let's check whether 3 is a valid bus size, we only need to check whether we have enough number of the multiples of 3 (i.e., 3, 6, 9, 12), in this case, check whether we have 12//3=4 of 3 multiples
looping over all terms showing up in the accumulate sum, we found only 3,4,6,12 has enough number of multiples, hence they are the only valid sizes