##Not an O(N^2) algorithm##
Not an O(N^2) algorithm
You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.
For each pair, you loop across the original vector of N elements.
Outer loop = O(N^2)
Inner loop = O(N)
Total = O(N^3)
By the way, unless you allow printing ranges of answers, there is no O(N^2) solution to this problem because there can be O(N^3) triplets that need to be printed.
##Not an O(N^2) algorithm##
You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.
For each pair, you loop across the original vector of N elements.
Outer loop = O(N^2)
Inner loop = O(N)
Total = O(N^3)
By the way, unless you allow printing ranges of answers, there is no O(N^2) solution to this problem because there can be O(N^3) triplets that need to be printed.
Not an O(N^2) algorithm
You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.
For each pair, you loop across the original vector of N elements.
Outer loop = O(N^2)
Inner loop = O(N)
Total = O(N^3)
By the way, unless you allow printing ranges of answers, there is no O(N^2) solution to this problem because there can be O(N^3) triplets that need to be printed.
##Not an O(N^2) algorithm##
You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.
For each pair, you loop across the original vector of N elements.
Outer loop = O(N^2)
Inner loop = O(N)
Total = O(N^3)
By the way, unless you allow printing ranges of answers, there is no O(N^2) solution to this problem because there can be O(N^3) triplets that need to be printed.
##Not an O(N^2) algorithm##
You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.
For each pair, you loop across the original vector of N elements.
Outer loop = O(N^2)
Inner loop = O(N)
Total = O(N^3)
##Not an O(N^2) algorithm##
You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.
For each pair, you loop across the original vector of N elements.
Outer loop = O(N^2)
Inner loop = O(N)
Total = O(N^3)
By the way, unless you allow printing ranges of answers, there is no O(N^2) solution to this problem because there can be O(N^3) triplets that need to be printed.