Thief and Warehouses
Practice
4.3 (64 votes)
Arrays
Data structures
Medium
One Dimensional
Stacks
Problem
62% Success 8481 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

There are N warehouses. The warehouses are located in a straight line and are indexed from 1 to N. Each warehouse contains some number of sacks.

A thief decides to rob these warehouses. Thief figured out that he can escape the police if and only if he follows both the following 2 constraints:

  • He will rob only one continuous segment of warehouses.
  • He will rob same number of sacks from each warehouse.

Thief wants to calculate the maximum number of sacks he can steal without getting caught by the police.

Input Format:

The first line contains an integer T denoting number test cases.

The first line of each test case contains a single integer N denoting number of warehouses.

The second line of each test case contains N space-separated integers :\(a[1],a[2],a[3]...a[n]. a[i]\) denotes number of sacks in \(i_{th}\) warehouse.

Constraints:

  • \(1 <= T <= 5\)
  • \(1 <= N <= 10^6\)
  • \(0 <= A[i] <= 10^{12}\)

Output Format:

Output exactly T lines.

The \(i_{th}\) line should contain a single integer, i.e the answer for \(i_{th}\) testcase(maximum number of sacks thief can steal without getting caught).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
27 votes
Tags:
Basic ProgrammingArraysImplementation1-DData Structures
Points:30
7 votes
Tags:
HashmapHashingCounting and ArrangementsData StructuresMathArrays1-D
Points:30
22 votes
Tags:
ArraysData StructuresMediumOne-dimensionalStandard Template Library