Problem: Sachin’s love for runs

Sachin always wanted to score more and more runs for his team. Sometimes he succeed in doing that and sometimes he fails.He also has a habit of noting down the runs he scored after every match in his diary. After matches he always look for his scores. In i-th match he score A[i] runs. Now he wanted to know the length of the maximum non-decreasing sub segment in sequence A. As he want to go for another match, help him in doing this task.

Input:
The first line contains T denoting the number of test cases . Then T test cases follow . The first line of each test case is an integer N . Then in the next line are N space separated values of the array A [ ] .

Output:
Print a single integer which denotes  the length of the maximum non-decreasing sub-segment.

Constraints:
1<=T<=30
1<=N<=105
1 ≤ A[ ] ≤ 109
Example:

Input    
2
6
2 2 1 3 4 1
3
2 2 9

Output
3
3

Explanation

In the first test the maximum non-decreasing sub-segment is  the segment with numbers from the third to the fifth one.

In the second test the maximum non-decreasing sub-segment is the numbers from the first to the third one.

Python: 2.7

t = input()
for _ in range(t):
    n = input()
    l = [int(x) for x in raw_input().strip().split()]
    start, lndss, temp = l[0], 1, 1
    #lnds = longest non-decreasing sub-segment
    for i in range(1, len(l)):
        if l[i] >= l[i-1]:
            temp += 1
        else:
            if temp > lndss:
                lndss = temp
            temp = 1
        if i == len(l)-1:
            if temp > lndss:
                lndss = temp

    print lndss
Advertisements