Longest Increasing Prefix Length
Programming Interview
Medium
4 views
Problem Description
For each testcase you get n numbers. Compute length of the longest prefix that is strictly increasing.
Input Format
First integer t. For each: n then n integers.
Output Format
t lines lengths.
Sample Test Case
Input:
2
5
1 2 3 2 5
4
10 20 30 40
Constraints
Sum of n over all testcases
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p:
sys.exit(0)
it=iter(p)
t=int(next(it))
out=[]
for _ in range(t):
n=int(next(it))
prev=None
ans=n
for i in range(n):
x=int(next(it))
if prev is not None and ans==n and x<=prev:
ans=i
prev=x
out.append(str(ans))
sys.stdout.write('\
'.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!