תיאור השאלה
You are given a string time in the form hh:mm, where some digits are hidden (represented by ?). Return the latest valid time you can get by replacing the hidden digits.
איך פותרים?
Fill each unknown digit greedily from left to right with the largest value that keeps the time valid.
פתרון קוד
JavaScript
Python
function maximumTime(time) {
const chars = time.split("");
if (chars[0] === "?") {
chars[0] = chars[1] === "?" || chars[1] <= "3" ? "2" : "1";
}
if (chars[1] === "?") {
chars[1] = chars[0] === "2" ? "3" : "9";
}
if (chars[3] === "?") {
chars[3] = "5";
}
if (chars[4] === "?") {
chars[4] = "9";
}
return chars.join("");
}הסבר וידאו כיצד לפתור את השאלה

לעבור את ראיון העבודה הבא שלך בהצלחה
קורס דיגיטלי מקיף עם +25 שיעורים מעשיים, כשעתיים של וידאו, וליווי של מראיין בכיר.