big o - Calculating the Big O of this algorithm -


I wrote the following code to reverse the string: How do I calculate large o? This was an interview question for the status of a junior developer.

  public static zero reverse string (string stroke) {string reversed = ""; Int lastIndex = str.lastIndexOf (""); While (last indicator! = -1) {reverse = + str.substring (last index + 1) + ""; Str = str.substring (0, last index); Previousindex = str.lastIndexOf (""); } Reverse + = str; Println (reverse); }   

O (n) lastIndexOf .

Comments