You are viewing a single comment's thread. Return to all comments →
I used this solution in C# :
using System; using System.Collections.Generic; using System.IO; class Solution { static void Main(String[] args) { int i, ctr=0, n = Convert.ToInt32(Console.ReadLine()); string str = Console.ReadLine(); int level = 0, flag = 0; for(i=0;i<n;i++){ if(str[i] == 'U'){ level++; } else{ level--; } if(level < 0){ flag = 1; } if(level >= 0 && flag == 1){ ctr++; flag=0; } } Console.WriteLine(ctr); } }
But I'm getting runtime error for the last few testcases. Im using the same logic but why is the error coming up?
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Valleys
You are viewing a single comment's thread. Return to all comments →
I used this solution in C# :
But I'm getting runtime error for the last few testcases. Im using the same logic but why is the error coming up?