clueless coding // TODO: be smarter

LeetCode Output Contest Matches: CPP Solution



TL;DR Code Solution


string findContestMatch(int n) {
    vector<string> matches(n);
    for (int i = 0; i < n; i++) {
        matches[i] = to_string(i + 1);
    }

    int current = n;
    while (current > 1) {
        for (int i = 0; i < current; i++) {
            matches[i] = "(" + matches[i] + "," + matches[current - i - 1] + ")";
        }
        current /= 2;
    }
    return matches[0];

}