preliminary solution
add O(n) solution