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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Regex
  3. Applications
  4. Find HackerRank
  5. Discussions

Find HackerRank

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 671 Discussions, By:

votes

Please Login in order to post a comment

  • [deleted] 4 years ago+ 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'
    
    8|
    Permalink
    View more Comments..
  • Mamduh
    5 years ago+ 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)
    
    6|
    Permalink
  • aswinkumar863
    1 year ago+ 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|
    Permalink
  • abramovtv
    2 years ago+ 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())))]
    
    3|
    Permalink
    View more Comments..
  • monishvm75
    10 months ago+ 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()))]
    
    1|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature