function check = ksubset_lex_check ( k, n, t )

%*****************************************************************************80
%
%% ksubset_lex_check() checks a K subset in lex form.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 January 2011
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Donald Kreher, Douglas Simpson,
%    Combinatorial Algorithms,
%    CRC Press, 1998,
%    ISBN: 0-8493-3988-X,
%    LC: QA164.K73.
%
%  Input:
%
%    integer K, the number of elements each K subset must have. 
%    0 <= K <= N.
%
%    integer N, the number of elements in the master set.
%    0 <= N.
%
%    integer T(K), describes a K subset.  T(I) is the I-th
%    element of the K subset.  The elements must be listed in ASCENDING order.
%
%  Output:
%
%    boolean CHECK.
%    true, the data is legal.
%    false, the data is not legal.
%
  check = true;

  if ( n < 0 )
    check = false;
    return
  end

  if ( k < 0 || n < k )
    check = false;
    return
  end
%
%  Items are between 0 and N, and in ascending order?
%
  tmin = 0;

  for i = 1 : k

    if ( t(i) <= tmin || n < t(i) )
      check = false;
      return
    end

    tmin = t(i);

  end

  return
end
