Python Interview Question: Find the Maximum Time from a Four-Digit Number|python |coding interview

Опубликовано: 12 Январь 2024
на канале: sumit kumar
133
11

In this Python tutorial, we'll explore how to find the maximum time in the "hh:mm" format, given a four-digit number that represents a time. Whether you're preparing for coding interviews or simply interested in solving a fun coding challenge, this video is for you! We'll break down the problem step by step, provide Python code examples, and explain the logic behind finding the maximum time. Join us on this journey of problem-solving and Python programming!

code used #code

import itertools


def max_time(num):
permutation=itertools.permutations(num)
max_time=-1
for i in permutation:
#print(i)
hh,mm=i[:2],i[2:]
print(hh,mm)
hr=int(''.join(map(str,hh)))
mn=int(''.join(map(str,mm)))
if 0 lt=hr lt 24 and 0lt =mn6 lt 0:
time=hr*60+mn
max_time=max(time,max_time)
if max_time==-1:
return "Invalid number"
hrs,mnt=divmod(max_time,60)
out=f"{hrs}:{mnt}"
return out

num=[9,2,9,4]
max_time(num)


На этой странице сайта вы можете посмотреть видео онлайн Python Interview Question: Find the Maximum Time from a Four-Digit Number|python |coding interview длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь sumit kumar 12 Январь 2024, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 133 раз и оно понравилось 11 зрителям. Приятного просмотра!