Simplest C++ solution (10 lines) using one sort function + comments + first try
This was my second attempt which was more performant and succinct (12ms > 90%):\n\nvector<string> reorderLogFiles(vector<string>& logs) {\n    // use stable_sor
This was my second attempt which was more performant and succinct (12ms > 90%):\n```\nvector<string> reorderLogFiles(vector<string>& logs) {\n    // use stable_sort as order of equivalent elements is preserved\n    stable_sort(logs.begin(), logs.end(), [](const string& a, const string& b){ \n        auto e1 = a.substr(a.find(\' \')  + 1); // get words not including identifier\n        auto e2 = b.substr(b.find(\' \') + 1);\n\n        // order if a || b are digit-logs\n        if (isdigit(e1[0]) && isdigit(e2[0])) return false;\n        if (isdigit(e1[0]) && !isdigit(e2[0])) return false;\n        if (isdigit(e2[0]) && !isdigit(e1[0])) return true;\n\n        // order if a && b are letter logs\n        auto diff = e1.compare(e2);\n        if (diff) return diff < 0;\n        return a.compare(b) < 0;\n    });\n    return logs;\n}\n```\n\nHere\'s my first attempt (16ms > 60%). It\'s a bit verbosed, I only realised I can do everything within one sort function after the fact:\n\n```\nvector<string> reorderLogFiles(vector<string>& logs) {\n    vector<string> res;\n    vector<string> digits;\n    vector<pair<string, string>> letters;\n\n    string id, entries;\n    for (const auto& log: logs) {\n        id = ""; entries = "";\n        for (const auto& c: log) {\n            if (c != \' \') { id += c; } else { break; }\n        }\n        entries = log.substr(id.size() + 1);\n        if (isdigit(entries[0])) {\n            digits.push_back(log);\n        } else {\n            letters.emplace_back(id, entries);\n        }\n    }\n\n    sort(letters.begin(), letters.end(), [](const pair<string, string>& a, const pair<string, string>& b){\n        return (a.second == b.second) ? a.first < b.first : a.second < b.second;\n    });\n    for (const auto& a: letters) {\n        res.push_back(a.first + " " + a.second);\n    }\n    res.insert(res.end(), digits.begin(), digits.end());\n    return res;\n}\n```\n\n
['C']