This Python script is designed to solve a problem of finding the first occurrence of an alphanumeric character that repeats in a given string. The script uses regular expressions, a powerful tool for string manipulation and parsing, to identify repeating characters.
CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷
The script works by taking an input string and using a regular expression to search for the first occurrence of any alphanumeric character that repeats. The regular expression used, '([A-Za-z0-9])\1', matches any alphanumeric character followed by the same character. If such a match is found, the script prints the character. If no match is found, the script prints -1.
import re
s = input()
res = re.search(r"([A-Za-z0-9])\1", s)
if res is None:
print(-1)
else:
print(res[1])
If you have a HackerRank coding test coming up, you can use CodeRankGPT to your advantage. It will assist you during your interview and help ensure you get the job.
AI is here now, and other candidates might be using it to get ahead and win the job. 🧐
The form has been successfully submitted.