Output Contest Matches


Hi @awice, I am unable to understand your lowest bit logic and in general, what is your algorithm intuition. Can you please provide a more detailed example and show the intuition.

@njucs.cxgmail.com I agree with you. I think even the time complexity should be O(n).
Time complexity = n + n/2 + n/4+ ... + 1 = 2n, so time complexity should be O(n).
Space complexity = O(4n3) = O(n)
Here's my C++ code:class Solution { public: string findContestMatch(int n){ vector<string> v; for(int i = 1; i<=n; i++){ v.push_back(to_string(i)); } while(v.size()!=1){ vector<string> temp; for(int i = 0; i<v.size()/2; i++){ temp.push_back("("+v[i]+","+v[v.size()1i]+")"); } v.clear(); v = temp; } return v[0]; } };