subject
Mathematics, 13.04.2021 02:50 Person51761

Right now you are doing a complete search over the prefix sums. However, this is not necessary. We know that the only way to get a multiple of $7$ is if both prefix sums have the same remainder $\pmod{ 7}$. Then, what happens if there are a lot of these prefix sums with the same remainder. If they're located at indexes $a_1,a_2,a_3,... ,a_n$, your $O(n^2)$ solution is finding the maximum of all of the differences. But we don't need to check $a_2-a_1$, for example, since we know $a_n-a_1$ is divisible by $7$, and it must be larger. Thus, we only have to find $a_1$ and $a_n$, because all the other differences must be smaller. This means that for each remainder from $0$ to $6$, we can calculate $a_1$ and $a_n$, and find the maximum of their difference, which will be an $O(n)$ solution.

ansver
Answers: 2

Other questions on the subject: Mathematics

image
Mathematics, 21.06.2019 15:00, lulustar13
Prove that 3: 8 is equivalent to 12: 32.a. use diagrams to support your answer.
Answers: 1
image
Mathematics, 21.06.2019 21:00, 22MadisonT
Abakery recorded the number of muffins and bagels it sold for a seven day period. for the data presented, what does the value of 51 summarize? a) mean of bagels b) mean of muffins c) range of bagels d) range of muffins sample # 1 2 3 4 5 6 7 muffins 61 20 32 58 62 61 56 bagels 34 45 43 42 46 72 75
Answers: 2
image
Mathematics, 21.06.2019 22:30, jacks0292
My hour hand points between the 8 and the 9 in 35 minutes it will be the next hour. what time is it ?
Answers: 2
image
Mathematics, 21.06.2019 22:50, ciaotaylor
1. if events a and b are non-overlapping events, how do you find the probability that one or the other occurs? 2. what does it mean if p(a or b) equals 1?
Answers: 2
You know the right answer?
Right now you are doing a complete search over the prefix sums. However, this is not necessary. We k...

Questions in other subjects:

Konu
Mathematics, 13.09.2020 18:01
Konu
Mathematics, 13.09.2020 18:01
Konu
Mathematics, 13.09.2020 18:01
Konu
Mathematics, 13.09.2020 18:01
Konu
Mathematics, 13.09.2020 18:01
Konu
Mathematics, 13.09.2020 18:01
Konu
Mathematics, 13.09.2020 18:01
Konu
Mathematics, 13.09.2020 18:01
Konu
Mathematics, 13.09.2020 18:01
Konu
Mathematics, 13.09.2020 18:01