Bob and Cakes
Practice
0 (0 votes)
Data structures
Math
Basic math
Arrays
Problem
78% Success 373 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Bob likes cakes very much and at the same time he is very health conscious.
In his village, there is a party going on where they have arranged \(N\) cakes in a row and each cake has a nutritious value \(a_i\) associated with it. If the nutritious value of any cake is \(\leq 0\) then Bob will fall sick after eating that cake.
Bob is very strict about how he eats his cakes, he will select a range \([l,r]\) and then start eating all the cakes in that range including \(l\) and \(r\)
So in how many ways Bob can choose \([l,r]\) such that he doesn't fall sick

Input :

The first line contains \(T\) , the number of test cases.

For each test case :

The first line contains \(N\), the number of cakes in the row.

The next line contain \(N\) integers, \(a_i\) the nutritious value of the \(i^{th}\) cake.

Output:

For each test case, print an integer value : the number of ways in which Bob can select a range \([l,r] \) where \(l \leq r\)

Note : The value may not fit in a 32-bit integer

Constraints : 

\(1 \leq T \leq 10^3\)

\(1 \leq N \leq 10^5\)

\(-10^9 \leq a_i \leq 10^9\)

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
Tags:
Basic ProgrammingMediumMath
Points:30
Tags:
Dynamic ProgrammingProbabilityCombinatoricsAd-HocMediumMathematicsOpenApprovedMathamatics
Points:30
13 votes
Tags:
Binary search algorithmMediumRecruitPrime FactorizationSegment treeMathematicsOpenApprovedMathematicsMathamatics