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, 20.06.2019 18:04
Abus ride for a senior citizen cost $1.25. a monthly pass costs $35. write and inequality that represents the number of times a senior citizen must ride the bus for the monthly pass to be a better deal.
Answers: 1
question
Mathematics, 21.06.2019 19:00
Sanya noticed that the temperature was falling at a steady rate of 1.4 degrees every hour from the time that she first checked her outdoor thermometer. by 6 a.m., the temperature had fallen 21 degrees. which expression can you use to find how many hours earlier she had first checked the thermometer?
Answers: 3
question
Mathematics, 21.06.2019 23:30
Answer each of the questions for the following diagram: 1. what type of angles are these? 2. solve for x. what does x equal? 3. what is the measure of the angles?
Answers: 1
question
Mathematics, 22.06.2019 00:00
What multiplys to be 1 but adds up to be 4
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
French, 08.02.2021 18:10
question
Mathematics, 08.02.2021 18:10
question
English, 08.02.2021 18:10
question
Mathematics, 08.02.2021 18:10
question
Mathematics, 08.02.2021 18:10
question
Geography, 08.02.2021 18:10
Questions on the website: 13722363