title: Smallest difference between two time values
body: <p>I need some help with a coding problem.</p>
  
  <p>Given a sequence of clock time values in hh:mm format, find the smallest difference in terms of minutes, between any two time values.</p>
  
  <p>For example, consider the following sequences of values:</p>
  
  <ol>
  <li><p>input = ['01:00','01:25'], smallest difference = 25 minutes</p></li>
  <li><p>input = ['11:00','12:02','11:58'], smallest difference = 4 minutes</p></li>
  <li><p>input = ['22:00','00:30'], smallest difference = 150 minutes</p></li>
  </ol>
  
  <p>In case 1, given the two values in the input sequence, the smallest difference is the number of minutes between the two clock time values, which is 25 minutes.</p>
  
  <p>In case 2, given the three values in the input, the smallest difference is the number of minutes between values '11:58' and '12:02'.</p>
  
  <p>In case 3, one needs to consider there are two ways to count the difference between two time values, in the clockwise and anti-clockwise direction. Going clockwise, the difference is 150 minutes, while going anti-clockwise, the difference is 1290 minutes. As the problem statement is about finding the smallest difference, the smaller value should be considered when computing the difference.</p>
  
  <p>Your task is to implement the details of the smallest_minute_difference function to determine the smallest difference between any two values in the provided list of input values. The algorithm is expected to return a number indicating the smallest difference, considering minutes as the unit of measurement. In the above cases, the function is expected to return 25, 4 and 150 respectively. The difference is expected to be a positive number, i.e. it is treated as an absolute value. The difference can be zero, if two similar time values are present in the input.</p>
  
  <p>The code that I've written:</p>
  
  <pre><code>import time
  from datetime import datetime
  def minimum_time_difference(timeInstants):
    timeInstants=sorted((time.strptime(d, "%H:%M") for d in timeInstants))
      fmt = '%H:%M'
      timeInstants=sorted(timeInstants)
      diff = '24:59' #I need to assign a very big value here
      diff = datetime.strptime(diff, fmt)
  
      n=len(timeInstants)
      for i in range(n):
          timeInstants[i] = datetime.strptime(timeInstants[i], fmt)
      for i in range(n): 
          print(timeInstants[i])
          if timeInstants[i+1] - timeInstants[i] &lt; diff: 
              diff = timeInstants[i+1] - timeInstants[i] 
  
      print(diff)
      return diff   
  
  def main():
    timeInstants = ['11:00','12:02','11:58']
    minimum_value = minimum_time_difference(timeInstants)
    message = 'Given time instant values {0}, minimum difference between any two time instants is {1}\n'.format(
        timeInstants, minimum_value)
    print(message)
  
  
  if __name__ == '__main__':
    main()
  </code></pre>
  
  <p>The code that I have written is giving me the error: </p>
  
  <pre><code>TypeError: unorderable types: datetime.timedelta() &lt; datetime.datetime
  </code></pre>
  
  <p>What am I doing wrong and is my approach correct?</p>