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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Regex
  3. Applications
  4. Detecting Valid Latitude and Longitude Pairs
  5. Discussions

Detecting Valid Latitude and Longitude Pairs

Problem
Submissions
Leaderboard
Discussions

Sort 114 Discussions, By:

recency

Please Login in order to post a comment

  • tuan26995
    2 weeks ago+ 0 comments

    pattern=re.compile('([+-]?(([1-8][0-9]|[0-9])(.[0-9]+)?|90(.0+)?), [+-]?((1[0-7][0-9]|[1-9][0-9]|[0-9])(.[0-9]+)?|180(.0+)?))')

    0|
    Permalink
  • ricardoandreh
    1 month ago+ 0 comments
    import re
    
    n = int(input())
    
    pattern = r"\A\([\-\+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s[\-\+]?([1-9]?\d(\.\d+)?|1[0-7]\d(\.\d+)?|180(\.0+)?)\)\Z"
    
    [print("Valid" if re.match(pattern, input()) is not None else "Invalid") for _ in range(n)]
    
    1|
    Permalink
  • avoscanemile
    2 months ago+ 0 comments

    I'm not quite sure these problems should be considered easy anymore (You have way easier regex problems in the Python practice set). Here's the code in Python, which looks like an alien trying to communicate with us.

    import re
    n_lines = int(input())
    for _ in range(n_lines):
        print('Valid' if bool(re.match(r'\(([+-]?[0-8]?[0-9](\.[0-9]+)?|[+-]?90(\.0+)?), ([+-]?1[0-7][0-9](\.[0-9]+)?|[+-]?180(\.0+)?|[+-]?0?[0-9]?[0-9](\.[0-9]+)?)\)', input())) else "Invalid")
    
    0|
    Permalink
  • tiagoiesbick
    2 months ago+ 0 comments

    Python 3

    import re
    p = re.compile(r'\((\+|-)?([0-9](\.\d+)?|[1-8][0-9](\.\d+)?|90(\.0+)?), (\+|-)?([0-9](\.\d+)?|[1-9][0-9](\.\d+)?|1[0-7][0-9](\.\d+)?|180(\.0+)?)\)')
    for _ in range(int(input())):
        s = input()
        if bool(re.search(p,s)):
            print('Valid')
        else:
            print('Invalid')
    
    0|
    Permalink
  • Bavly_Zaher
    4 months ago+ 0 comments
    import re
    N = int(input())
    for _ in range(N):
        LL = input()
        if re.search(r"^\([+-]?(([0-9]|[1-8][0-9])(\.\d+)?|90(\.0+)?), [+-]?(([0-9]{1,2}|1[0-7][0-9])(\.\d+)?|180(\.0+)?)\)",LL):
            print("Valid")
        else :
            print("Invalid")
    
    0|
    Permalink
Load more conversations

Need Help?


View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy