Maximum Possible Time Problem Statement

Given an array ARR consisting of exactly four integer digits, your task is to form the maximum possible valid time in a 24-hour format using those digits.

Explanation:

The 24-hour time format ranges from 00:00 to 23:59. If it's not possible to generate a valid time from the given digits, return -1.

Input:

T
ARR[0] ARR[1] ARR[2] ARR[3]
...(for each test case T)

Output:

Maximum time in HH:MM format for each test case or -1 if no valid time can be generated.

Example:

Input:
1
1 2 3 4
Output:
23:41

Constraints:

  • 1 <= T <= 10
  • 0 <= ARR[i] <= 9
  • Time Limit: 1 second

Note:

You do not need to print anything; the code should return the valid string representation of the time.

AnswerBot
1d

Given an array of four digits, form the maximum valid 24-hour time. Return -1 if not possible.

  • Iterate through all permutations of the digits to find the maximum valid time.

  • Check if the time is valid (...read more

Help your peers!
Add answer anonymously...
Blinkit Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter