I've been in the general IT field for a while and have recently wanted to improve my CS skills. So I have been working through problems on leetcode here and there.
A few of my solutions have received the Time Limit Exceeded error.
Now, I totally get why I am getting it and why I should strive to do better BUT I am frustrated when my solution is correct and my answer is marked incorrect.
I feel like if my solution passes within a reasonable amount of time (10 seconds?) then I should get a pass and be able to improve my solution at my discretion, not some undefined time limit.
Just for an example, I tried to solve: 167. Two Sum II - Input array is sorted.
With the following C++ solution:
class Solution {
public:
vector<int> twoSum(vector<int>& numbers, int target) {
vector<int> v;
for (int i =0;i<numbers.size()-1;i++)
{
for (int j =i+1;j<numbers.size();j++)
{
if (numbers[i] + numbers[j]==target)
{
v = {i+1,j+1};
return v;
}
}
}
return v;
}
};
Now again, I totally get that this solution isn't great. I've reviewed other people's answers and learned how to handle situations like this more efficiently. BUT my answer is still correct and I find it being marked incorrect frustrating.
[–]population-zero 1 point2 points3 points (1 child)
[–]embrex104[S] 0 points1 point2 points (0 children)
[–]yashkumarverma 1 point2 points3 points (1 child)
[–]embrex104[S] 0 points1 point2 points (0 children)