Why getting buffer overflow exception
I have below code which works well for all the test cases except for one testcase where vector has 10000 entries. For this test case I\'m getting heap buffer ov
I have below code which works well for all the test cases except for one testcase where vector<string> has 10000 entries. For this test case I\'m getting heap buffer overflow exception. \n\nAny reasons why I\'m getting heap buffer overflow exception for below code? \n**Code that doesn\'t work**\n```\nstring kthLargestNumber(vector<string>& nums, int k) {\n        \n        sort(nums.begin(), nums.end(), [](string &i,string &j){\n            auto i_len = i.length();\n            auto j_len = j.length();\n            if(j_len > i_len)\n                return false;\n            if(j_len < i_len)\n                return true;\n       \n            int ret = i.compare(j);\n            if(ret < 0)\n                return false;\n            if(ret > 0)\n                return true;\n       \n            return true;\n        });\n        \n        if(nums.size() >= k)\n            return nums[k-1];\n        else \n            return {};\n    }\n```\n\nThe same code works when comparator function is changed to \n**This code works**\n```\nsort(nums.begin(), nums.end(), [](string &i,string &j){\n\tif(i.length() == j.length()) {\n\t\treturn j < i;\n\t} \n\t\n\treturn j.length() < i.length();\n});\n```\n
[]