a linear solution, will add a binary search solution later