File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/bin/python3
2+
3+ import math
4+ import os
5+ import random
6+ import re
7+ import sys
8+
9+ #
10+ # Complete the 'countingValleys' function below.
11+ #
12+ # The function is expected to return an INTEGER.
13+ # The function accepts following parameters:
14+ # 1. INTEGER steps
15+ # 2. STRING path
16+ #
17+
18+ def countingValleys (steps , path ):
19+ # Write your code here
20+ level = valley = 0
21+
22+ for i in range (steps ):
23+ if path [i ] == "U" :
24+ level += 1
25+ if level == 0 :
26+ valley += 1
27+ else :
28+ level -= 1
29+ return valley
30+
31+ if __name__ == '__main__' :
32+ fptr = open (os .environ ['OUTPUT_PATH' ], 'w' )
33+
34+ steps = int (input ().strip ())
35+
36+ path = input ()
37+
38+ result = countingValleys (steps , path )
39+
40+ fptr .write (str (result ) + '\n ' )
41+
42+ fptr .close ()
You can’t perform that action at this time.
0 commit comments