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 16:20
To prove that def ~ gfh by the sss similarity theorem using the information provided in the diagram, it would be enough additional information to know that
Answers: 3
question
Mathematics, 21.06.2019 18:00
Sandy is ordering bread rolls for her party,she wants 3/5 of the rolls to be whole wheat. what other factions can represent part of the rolls that will be whole wheat? shade the models to show your work.
Answers: 1
question
Mathematics, 21.06.2019 19:20
Which of the following quartic functions has x = –1 and x = –2 as its only two real zeroes?
Answers: 1
question
Mathematics, 21.06.2019 20:30
What is the slope of the line shown below?
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
Social Studies, 23.10.2019 01:50
question
English, 23.10.2019 02:00
Questions on the website: 13722363