educative.io

Approach 2 is O(n^2)

Since there are for loops and the inner for loop running till end of string it is actually O(N^2). Please correct me if wrong

Hi @Nanda_Adithyan

The inner loop will run O(n) times as the inner loop is checking if the character already exists or not, if found it will break the loop and such traversal is done in linear time i.e O(n). The outer loop is also taking O(n) as it will run till length of string thus total time complexity would be O(n^2).