Sequence Artisan
InterviewTime limit1sMemory limit256 MB
Find the largest product of any contiguous block in an array with values from -2 to 2, then report it modulo 1000000007.
- Level
Medium5 of 10
- Topics
- Greedy, Dynamic programming, Math
- Solved
- No attempts yet
Problem
Seunghyun builds sequences of length for customers who need one. He is early in his career, so he can only build sequences whose elements are integers between and , and few customers come to him.
Jihak ordered a sequence from him. From the finished sequence Jihak picks one contiguous block () and wants the product of its elements, , to be as large as possible. If , the product is .
Given the sequence Seunghyun built, find the largest product Jihak can obtain.
Input
The first line contains the number of test cases (). The test cases follow.
The first line of each test case contains the length of the sequence (). The second line contains the elements (), separated by spaces.
The sum of over all test cases does not exceed .
Output
For each test case, print the largest product modulo () on its own line.
Compare the true products when choosing the largest one, then reduce only that chosen value modulo .