text: # https://www.hackerrank.com/challenges/counting-valleys/problem
  # disregard the process, only check if the after each Up step,
  # the altitude is ZERO or not
  
  def countingValleys(n, s):
      alt = 0
      valleys = 0
  
      for step in list(s):
          if step == 'U':
              alt += 1
              if alt == 0:
                  valleys += 1
          elif step == 'D':
              alt -= 1
      
      return valleys
  
  
  n = 8
  s = 'UDDDUDUU'
  
  print(countingValleys(n, s))
  
  n = 8
  s = 'DDUUUUDD'
  print(countingValleys(n, s))