Basic solution using sequential for loop