leastOccurrences method

(bool, int)? leastOccurrences()

Finds the least common value in the list.

Returns a record (tuple) containing the least common value and its frequency. If the list is empty, returns null.

Implementation

(bool, int)? leastOccurrences() {
  if (isEmpty) {
    return null;
  }

  final int trueCount = countTrue;
  final int falseCount = length - trueCount;

  // When counts are equal, false is returned (consistent behavior)
  if (falseCount <= trueCount) {
    return (false, falseCount);
  }
  return (true, trueCount);
}