hackerrank/interview_preparation_kit_warm_up_challenges.rb
# Complete the countingValleys function below.

Complete the countingValleys function below.
Complete the countingValleys function below .
def countingValleys(n, s)
  high = 0
  valley = 0
  s.split("")
    .map(&lambda do |t|
       case t
       when "U" then 1
       when "D" then -1
       end
     end)
    .each(&lambda do |i|
       if high == 0
         high = high + i
         valley += 1 if high < 0
       else
         high = high + i
       end
     end)
  valley
end
def countingValleys ( n , s ) high = 0 valley = 0 s . split ( "" ) . map ( & lambda do | t | case t when "U" then 1 when "D" then - 1 end end ) . each ( & lambda do | i | if high == 0 high = high + i valley += 1 if high < 0 else high = high + i end end ) valley end
Complete the countingValleys function below.
Complete the countingValleys function below .
n
<not_specific>
s
<not_specific>