title: Maximize digits in 24 hour format.
body: <p>Came across this question in a Glassdoor review and thought it was interesting. </p>
  
  <blockquote>
    <p>Given an integer consisting of 4 digits, we need to maximize it in 24
    hour format. For example, 4372 should return a String of the form
    23:47, which is the maximum 24 hour value that can be obtained from
    the given integer. Assume the given integer always contains exactly 4 digits.</p>
  </blockquote>
  
  <p>Here's an <strong>incomplete</strong> method I wrote trying to solve it:</p>
  
  <pre><code>private static String maximize24Hour(int digits) {
      if (digits == 0)
          return "00:00";
      if (digits &lt; 0)
          return null;
  
      ArrayList&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      do {
          list.add(digits % 10);
          digits /= 10;
      } while (digits != 0);
  
      // Extra processing needs to be done here. Haven't figured it out. 
  
      StringBuilder buf = new StringBuilder();
      for (Integer d : list) {
          buf.append(d);
      }
  
      String result = buf.toString();
      String hours = result.substring(0, 2);
      String minutes = result.substring(2, result.length()); 
  
      if (Integer.parseInt(result) &gt; 2359 
              || Integer.parseInt(hours) &gt; 23 
              || Integer.parseInt(minutes) &gt; 59
              || result.length() != 4)
          return null;
  
      return hours.concat(":").concat(minutes);
  }
  </code></pre>
  
  <p>Am I even approaching it correctly? If this was just any number, it would be trivial. But it's asking for it to be in 24 hour format which is what I find tricky. </p>
  
  <p>I'd be interested to see if anyone has solutions/ideas for this challenge.  </p>