--Explained in easy language with the solution--


#1

Here the main trick is that j is declared as the global variable. and the array is just for the confusion it is of no use.
Now let’s say in 1st iteration in the worst-case let’s say j runs for n times. Now for the 2nd iteration, it won’t be 0 again it will remain n because the global variable is changed.
Therefore for every other iteration, it won’t enter the while loop therefore total time taken.
Statement 1 - 1unit
Statement 2 - N times
Statement 3 - 1 unit(Only for the first iteration when i=0)
Statement 4 - 1 unit
Total time = 1+N+1+1
Therefore worst-case time complexity is O(N).


#2

Thanks bro it is indeed an easy explanation .