3361. Latest Time You Can Obtain After Replacing Characters
My accepted Python solution to LeetCode problem 3361, Latest Time You Can Obtain After Replacing Characters, running in 40ms.
- Difficulty: Easy
- Python
- Runtime 40ms
- Memory 17.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 40ms, memory 17.5MB, accepted 2026-01-01.
class Solution:
def findLatestTime(self, s: str) -> str:
s = list(s)
# Hour first digit (0 or 1)
if s[0] == '?':
s[0] = '1' if s[1] == '?' or s[1] <= '1' else '0'
# Hour second digit
if s[1] == '?':
s[1] = '1' if s[0] == '1' else '9'
# Minute first digit (0-5)
if s[3] == '?':
s[3] = '5'
# Minute second digit (0-9)
if s[4] == '?':
s[4] = '9'
return ''.join(s)