implement findNthElement optimization version, linear time