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 12:30
To complete your spring schedule, you must add calculus and physics. at 9: 30, there are three calculus sections and two physics sections; while at 11: 30, there are two calculus sections and three physics sections. how many ways can you complete your schedule if your only open periods are 9: 30 and 11: 30?
Answers: 2
question
Mathematics, 21.06.2019 14:20
Which function families have maximums and minimums? 1.)linear absolute value functions and exponential functions 2.) linear absolute value functions and quadratic functions 3.) linear absolute value functions and linear functions 4.) linear absolute value functions and constant functions
Answers: 2
question
Mathematics, 21.06.2019 15:10
The amount of energy it takes to lift a box might be a function of which of the following
Answers: 1
question
Mathematics, 21.06.2019 16:30
Which elements in the set below are integers? 12, –3⁄4,√ 25 , –7, √ 5 , 14⁄7, 9 a. 12, √ 25 , –7, 9 b. 12, √ 25 , –7, 14⁄7, 9 c. –3⁄4, 25 , √ 5 ,14⁄7 d. 12, –7, 9
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
question
French, 19.03.2020 21:04
question
Mathematics, 19.03.2020 21:04
question
Mathematics, 19.03.2020 21:04
Questions on the website: 13722367