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.
- Prepare
- Regex
- Applications
- Find HackerRank
- Discussions
Find HackerRank
Find HackerRank
[deleted] + 10 comments Bash.
starts='^hackerrank.+' ends='.+hackerrank$' both='^(hackerrank).*\1?$' sed -E \ -e '1d' \ -e "s/$starts/1/" \ -e "s/$ends/2/" \ -e "s/$both/0/" \ -e '/1|2|0/! c\-1'
+ 2 comments import re for _ in range(int(input())): s=input() if re.search(r'^hackerrank(.*hackerrank)?$',s): print(0) elif re.search(r'^hackerrank',s): print(1) elif re.search(r'hackerrank$',s): print(2) else: print(-1)
+ 3 comments JavaScript (Node.js) - Without Conditional Statements
let [n, ...s] = input.trim().split('\n') s.forEach(i => { let [, start='', end=''] = i.match(/(.)*hackerrank(.)*/) || [] console.log([[0, 1], [2, -1]][start.length][end.length]) })
+ 4 comments Why should we use regex? Why should we use more than one line on Python? Ok, I'm just kiddin', never do like this:
[print((0 if s.endswith(h) else 1) if s.startswith(h) else (2 if s.endswith(h) else -1 )) for s, h in ((input(), 'hackerrank') for _ in range(int(input())))]
+ 1 comment import re def statusCode(text): match = re.search(pattern, text) if(match !=None): if(match.group(1) == searchKey): print('0') elif(match.group(2) == searchKey): print('1') elif(match.group(3) == searchKey): print('2') else: print('-1') searchKey = 'hackerrank' pattern = r'(?:^({0})$|(^{0})|({0}$))'.format(searchKey) text = [statusCode(input()) for i in range(int(input()))]
Load more conversations
Sort 671 Discussions, By:
Please Login in order to post a comment