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.
functionhackerrankInString(s:string):string{/** * idea is simple * * 1. create 2 array of 'hackerrank' and 's' that hold it characters * 2. loop ... * reduce [s] * reduce [hackerrank] too if both starting element is same * if [hackerrank] empty first, go 'YES' * if [s] empty first, go 'NO */let_h='hackerrank'.split('')let_s=s.split('')while(true){if(_h.length==0)return'YES'if(_s.length==0)return'NO'_s[0]==_h[0]&&_h.shift()_s.shift()}}
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 →
My answer in Typescript, simple, not minimized