Exercise 3.24: hasSubsequence