C++ || Custom sorting comparator
Find the Kth Largest Integer in the Array\n---\n### \uD83D\uDCDD | Explanation\nNote: We are given that, numbers in strings are given such that there are not le
## Find the Kth Largest Integer in the Array\n---\n### \uD83D\uDCDD | Explanation\n**Note:** We are given that, *numbers in strings are given such that there are not leading zeros, except zero itself.*\n\nAbove constraint simplifies our task.\nLet, `nums = ["2","21","12","1"]`.\nLet, `a` and `b` be string representation of some number `x` and `y`.\n**Case 1: `if a.size() == b.size()`**\n - then lexicographically larger string represents larger number. and vice-versa\n - Ex: `a="142"`, `b="145"`\n\t - since length of `a` and `b` are equal, and `b` is lexicographically larger, hence `b` is largest number among them, i.e. 145.\n\n**Case 2: `if a.size() != b.size()`**\n\n- then string with smaller length will represent smaller number and vice-versa.\n- Ex: a="10", b="123"\n\t- since lenght of `a` is smaller than that of `b`, `a` will represent a smaller numerical value than `b` for sure.\n\nWe can now use this concept to design a custom sorting comparator and find out kth largest number in array.\n\n---\n\n### \uD83E\uDDD1\u200D\uD83D\uDCBB | Code\n```\nclass Solution {\npublic:\n    string kthLargestNumber(vector<string>& nums, int k) {\n        sort(nums.begin(), nums.end(), [](const string a, const string b){\n\t\t\t// if lenght of both the strings is equal, lexicographically \n\t\t\t// smaller string should come first after sorting\n            if(a.size()==b.size()){\n                return a<b;\n            }\n\t\t\t// else string with lesser length, comes first in sorted order.\n            return a.size()<b.size();\n        });\n\t\t// return the kth element from the end \n\t\t// (bcoz array is sorted in ascending order.)\n        return nums[nums.size()-k];\n    }\n};\n```\n\n-----\nDo upvote if it helped you.\nThanks for reading.\uD83D\uDE01
['String', 'Sorting']