Near-optimal Offline and Streaming Algorithms for Learning Non-Linear Dynamical Systems