Count Balanced Numbers in a Permutation
Given a permutation p of length n, a number k is balanced if there exist indices l, r (1 ≤ l ≤ r ≤ n) such that [p[l], p[l+1], ..., p[r]] is a permutation of the numbers 1, 2, ..., k.
For each k (1 ≤...
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Standard Input
Execution Result:
