module solution_5_4
public  ::  earliest
contains
! Solution 5/4
   function earliest(string) result(e)
      character (len=*), intent(in) :: string
      character(len=1) :: e
      integer          :: j, length
      length = len(string)
      if (length <= 0) then
         e = ""
      else
         e = string(1:1)
         do j = 2, length
            if (string(j:j) < e) then
               e = string(j:j)
            end if
         end do
      end if
   end function earliest
end module solution_5_4
