We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
staticStringhackerrankInString(Strings){// Complete this functionStack<Character>stack=newStack<>();stack.push('k');stack.push('n');stack.push('a');stack.push('r');stack.push('r');stack.push('e');stack.push('k');stack.push('c');stack.push('a');stack.push('h');Stringresult="NO";for(Characterc:s.toCharArray()){if(c==stack.peek())stack.pop();if(stack.isEmpty()){result="YES";break;}}returnresult;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
HackerRank in a String!
You are viewing a single comment's thread. Return to all comments →
Java soln using Stacks :)