You have three loops that you need to analyze. The first two are a set of nested loops: every time the inner (j) loop runs n
times, the outer (i) loop runs once. Because the outer loop eventually runs n
times, the whole set will run n*n = n^2
times, so we say that set of loops runs in O(n^2) time. Once these loops complete, the third (k) loop runs n
times, which is O(n) time.
When you have two separate operations with different big-O complexities and want to add the complexities together to get their total, you take the larger of the two. Since O(n^2) is "larger" than O(n), we say that the entire program runs in O(n^2) time.