Alternative implementation O(n^2).

Signed-off-by: mitkof6 <jimstanev@gmail.com>