Count The Valleys
All submissions for this problem are available.
Manjunath and Sushrut are planning to go to Himalayan mountains. But before going there, they want to find out how many valleys are there at the moutainside. So, you have to count the valleys for them.
You are given an array A of integers of size N which denotes mountain heights.You have to find how many valleys are there .Valley is defined as an index i if A[i-1]>A[i] and A[i]< A[i+1].
First line consist of an integer T denoting number of testcases.
first line of each testcase consist of an integer N indicating size array followed by N integers denoting mountain heights.
Outputfor each testcase,output number of valleys in the newline.
- 1 ≤ T ≤ 100
- 1 ≤ N ≤ 105
- 0 ≤ A[i] ≤ 105
Input 2 7 1 4 3 8 6 10 7 4 4 8 6 10 Output 2 1
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.