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
  • Hiring developers?
  1. Prepare
  2. Python
  3. Regex and Parsing
  4. Validating Postal Codes
  5. Discussions

Validating Postal Codes

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • dmitrius988
    2 months ago+ 1 comment

    ChatGPT and passed all tests:

    import re

    regex_integer_in_range = r"^[1-9][0-9]{5}$" regex_alternating_repetitive_digit_pair = r"(\d)(?=\d\1)"

    P = input()

    print(bool(re.match(regex_integer_in_range, P)) and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)

    -1|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy