We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ea163dc commit 3f5bbfbCopy full SHA for 3f5bbfb
HackerRank-Counting Valleys/Counting_Valleys.py
@@ -0,0 +1,33 @@
1
+#!/bin/python3
2
+
3
+import math
4
+import os
5
+import random
6
+import re
7
+import sys
8
9
+# Complete the countingValleys function below.
10
+def countingValleys(n, s):
11
+ level=valley=0
12
+ for i in range(n):
13
+ if(s[i]=='U'):
14
+ level+=1
15
+ if(level==0):
16
+ valley+=1
17
+ else:
18
+ level-=1
19
20
+ return valley
21
22
+if __name__ == '__main__':
23
+ fptr = open(os.environ['OUTPUT_PATH'], 'w')
24
25
+ n = int(input())
26
27
+ s = input()
28
29
+ result = countingValleys(n, s)
30
31
+ fptr.write(str(result) + '\n')
32
33
+ fptr.close()
0 commit comments