A coding problem I'm thinking about (I don't know the solution).

Input: a string with N,S,W,E representing a path on a grid.
Output: whether the path revisits at least one cell.

If T is the time complexity and S is the space complexity, can you get T*S to be less than O(n^2)?