Find maximum possible time HH:MM by permuting four given digits

前端 未结 23 2074
执念已碎
执念已碎 2020-11-30 02:44

I recently took a coding test for a promotion at work. This was one of the tasks I really struggled with and was wondering what is the best way to do this. I used a load of

23条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 03:02

    For places, AB:CD,

    If at any point a condition cannot be fulfilled:
      return NOT POSSIBLE
    
    If there are two numbers greater than 5:
      place the larger in B, smaller in D
    
    for non-filled places from left to right:
      if B > 3:
        place a 1 in A
      else:
        place the largest number smaller than 3 in A
    
      if A is 2:
        place the largest number smaller than 4 in B
      else:
        place the largest number in B
    
      place the largest number smaller than 6 in C
      place the remaining number in D
    

提交回复
热议问题