implement function verify it's right by comparing to naive approach
implement function
verify it's right by comparing to naive approach