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 20:00
Parabolas y=βˆ’2x^2 and y=2x^2 +k intersect at points a and b that are in the third and the fourth quadrants respectively. find k if length of the segment ab is 5.
Answers: 1
question
Mathematics, 21.06.2019 20:00
What’s the answer ? use the picture to see the problem
Answers: 2
question
Mathematics, 21.06.2019 22:00
In dire need~! describe how to use area models to find the quotient 2/3 divided by 1/5. check your work by also finding the quotient 2/3 divided by 1/5 using numerical operations only.
Answers: 3
question
Mathematics, 22.06.2019 01:00
3questions show how you solved the problem 1. subtract & simplify (–y2 – 4y – 8) – (–4y2 – 6y + 3) 2.multiply and simplify 2x2y3z2 Β· 4xy4x2 3.multiply and simplify (x – 4) (x2 – 5x – 6)
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
Mathematics, 10.10.2019 11:10
Questions on the website: 13722367