Great explanation. However, the time complexity isn't O(n^2) but O(n^3). This is because constructing and comparing the substring in the if statement takes O(n) time in the worst case. You can still get an O(n^2) solution using rolling hash :) mohammedshoaib
Great explanation. However, the time complexity isn't O(n^2) but O(n^3). This is because constructing and comparing the substring in the if statement takes O(n) time in the worst case. You can still get an O(n^2) solution using rolling hash :)