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

Another question on Mathematics

question
Mathematics, 21.06.2019 18:00
The given dot plot represents the average daily temperatures, in degrees fahrenheit, recorded in a town during the first 15 days of september. if the dot plot is converted to a box plot, the first quartile would be drawn at __ , and the third quartile would be drawn at __ link to graph: .
Answers: 1
question
Mathematics, 22.06.2019 00:40
The length of the line segment ac is 8x-9 what is the value of x
Answers: 2
question
Mathematics, 22.06.2019 04:20
The width of a piece of rectangular land is 5m shorter rhan 1/3 of its length .find the width of the land if the length is 60m,150m.
Answers: 2
question
Mathematics, 22.06.2019 04:30
You estimate that a baby bird weighs 2 pounds. the actual weight of the baby bird is 1.5 pounds. find the percent error. round your answer to the nearest hundredth of a percent.
Answers: 1
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
question
Computers and Technology, 24.10.2019 20:43
question
History, 24.10.2019 20:43