Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Examples to Understand Time Complexity.
int foo(vector<int> &nums) {
int maximum = 0; // 1
for (int i=0; i<n; i++) { // n times
maximum = max(maximum, nums[i]); // 1
}
int minimum = 0; // 1
for (int i=0; i<n; i++) { // n times
minimum = min(minimum, nums[i]); // 1
}
int sum = 0; // 1
for (int i=0; i<n; i++) { // n times
for (int j=0; j<n; j++) { // n times
sum += maximum + minimum + nums[i] + nums[[j]; // 4
}
}
return sum; // 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.