Here is a logical explaination
Ver. 18. None is good. Of himself, entirely and essentially, but God alone: men may be good also, but only by a participation of God’s goodness. (Challoner)
Ver. 20. We must recollect, that to the faithful observers of the Mosaic law, not only present goods were given, but the happiness of a future life promised. Hence our Lord with reason inquired, whether he had kept the commandments. The innocent life of this young man is deserving of our imitation. (Ven. Bede)
I don’t know how much more clear to have it explained