This solution gives similar performance results than the tree based one, mostly because of the intermediate vectors.