C++ Two Simple and Easy 4-Line Solutions, O(nlogn) / O(n), Explained
Solution I:\nSort the array using custom sort (otherwise we will get lexicographical order), then return kth largest.\nTime Complexity: O(nlogn)\nSpace Complexi
**Solution I:**\nSort the array using custom sort (otherwise we will get lexicographical order), then return kth largest.\n**Time Complexity:** O(nlogn)\n**Space Complexity:** O(1)\n```\nclass Solution {\npublic:\n    static bool comp(string& a, string& b) {\n        if (a.size() != b.size()) return a.size() < b.size();\n        return a < b;\n    }\n    \n    string kthLargestNumber(vector<string>& nums, int k) {\n        sort(nums.begin(), nums.end(), comp);\n        return nums[nums.size()-k];\n    }\n};\n```\n****\n**Solution II:**\nActually, we don\'t need to sort the whole array. We just need to find which element would appear in the nth largest index after sorting.\nWe have a built-in function to do exactly that with linear time complexity.\n**Time Complexity:** O(n)\n**Space Complexity:** O(1)\n```\nclass Solution {\npublic:\n    struct comp {\n        bool operator()(const std::string& a, const std::string& b) const {\n            if (a.size() != b.size()) return a.size() < b.size();\n            return a < b;\n        }\n    };\n    \n    string kthLargestNumber(vector<string>& nums, int k) {\n        nth_element(nums.begin(), nums.end()-k, nums.end(), comp());\n        return nums[nums.size()-k];\n    }\n};\n```\n**Like it? please upvote!**
['C']