- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python - Find the latest valid time that can be obtained by replacing the unknown/hidden digits
When it is required to find the valid time which can be obtained by replacing unknown digits, a method is defined that checks to find the unknown/hidden digit, and then converts it into a different value depending on the value present in the index.
Below is a demonstration of the same
def find_latest_time(my_time): my_time = list(my_time) for i in range(len(my_time)): if my_time[i] == "?": if i == 0: my_time[i] = "2" if my_time[i+1] in "?0123" else "1" elif i == 1: my_time[i] = "3" if my_time == "2" else "9" elif i == 3: my_time[i] = "5" else: my_time[i] = "9" print("".join(my_time)) my_str = '0?:?3' print("The time is :") print(my_str) print("The latest valid time is : ") find_latest_time(my_str)
The time is : 0?:?3 The latest valid time is : 09:53
A method named ‘find_latest_time’ is defined that takes a time as a parameter.
It is converted to a list.
It is iterated over and checked to see for the hidden/unknown time values.
If the value of the iterator is 0 or 1 or 3, it is replaced with a specific value.
Outside the method, a string is defined, and is displayed on the console.
The method is called by passing this value.
The output is displayed on the console.
- Program to find latest valid time by replacing hidden digits in Python
- Find maximum points which can be obtained by deleting elements from array in Python
- Find the largest number that can be formed with the given digits in C++
- Maximum possible time that can be formed from four digits in C++
- Find maximum points which can be obtained by deleting elements from array in C++
- Maximize the given number by replacing a segment of digits with the alternate digits given in C++
- Count of distinct sums that can be obtained by adding prime numbers from given arrays in C++
- Indicate collapsible content that can be hidden or shown with Bootstrap
- Python Program to find out the number of rooms in which a prize can be hidden
- Check if a string can be obtained by rotating another string 2 places in Python
- Maximum array sum that can be obtained after exactly k changes in C++
- Program to find nearest time by reusing same digits of given time in python
- Maximize the value of A by replacing some of its digits with digits of B in C++
- How can you order the result obtained by select query in MySQL?
- Find maximum number that can be formed using digits of a given number in C++