I came across an interesting algorithm task:
Given an integer array, find the number of unordered pairs in this array, say, given {1, 3, 2}, answer 1, because {3, 2} is not ordered, and for the array {3, 2, 1}, answer 3 , because {3, 2}, {3, 1}, {2, 1}.
Obviously, this can be resolved by brute force with a runtime of O (n ^ 2) or rearrange all possible pairs, and then eliminate those invalid pairs.
My question is, does any solution have any solution, and how do you do it, because it seems like a dynamic programming problem. Code snippet will be useful
arrays algorithm dynamic-programming
Mighty_L
source share