Statistical Mode calculation in Arduino programme
First, two caveats: (a) The question is fairly general and might be better asked on stackoverflow, except that asking here will tend to focus answers on algorithms with low memory requirements or online methods (methods that continually compute an answer as data streams through).  (b) In many cases – eg, with noisy sensors, noisy inputs, changing inputs – the statistical mode is less likely to be relevant than the statistical mean or median.

What computation method is best depends on which model of Arduino you use (because available RAM depends on model), what range of data your distance sensor returns, how many readings are taken, what you want to do with the data, whether an approximate (or nearly-correct) answer is acceptable vs an exact answer, and so forth.

Assuming you take 30 readings and store the data in an array d (that is, in d[0] ... d[29]), you could act as follows:


  Set high-value and high-count variables, say hiv and hic, both to 0.  For i from 0 to 29, count the number of occurrences ni of the value d[i] in the d array.  Whenever ni exceeds hic, set hic to ni and hiv to d[i].


You could make this more elaborate by detecting whether hiv is already equal to d[i] and testing ni ≥ hic rather than ni > hic.  This would allow detecting cases where two values are modal.

The method suggested in a comment – counting number of readings in various intervals – may compute an incorrect answer because the interval with the highest total count need not be the interval the mode is in.