Wrote the function to check the solution