im learning now data structure and i just write a code and i dont know very well how to compute the time complexity of the code. i need to count the frequent of words in sorted string array. i think that if i write a code with for loop thats end in (n) thats O(n) and if inside the loop there is while loop that goes until length - 1 is O(n-1) so the time complexity is O(n^2).
and this is my code. thanks for all!
int length = array.length;
for (int i = 0; i < length - 1; i++) {
int counter = 1;
while(i< length - 1 && array[i] == array[i+1]) {
counter++;
i++;
}
System.out.print(counter +" ");