Error : runtime error


#1

/**

  • Definition for an interval.

  • struct Interval {

  • int start;
    
  • int end;
    
  • Interval() : start(0), end(0) {}
    
  • Interval(int s, int e) : start(s), end(e) {}
    
  • };
    */
    bool mycomp(Interval a, Interval b)
    {
    return a.start < b.start;
    }
    vector Solution::merge(vector &A) {
    // Do not write main() function.
    // Do not read input, instead use the arguments to the function.
    // Do not print the output, instead return values as specified
    // Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details
    int n = sizeof(A)/sizeof(A[0]);
    vector ans;
    int k = 0;
    sort(A.begin(), A.end(), mycomp);
    int index = 0;
    for (int i = 1; i < n; i++)
    {
    if (A[index].end >= A[i].start)
    {
    A[index].end = max(A[i].end, A[index].end);
    A[index].start = min(A[index].start, A[i].start);
    }
    else
    {
    index++;
    A[index] = A[i];
    }

    }
    for (int i = 0; i <= index; i++)
    {
    ans[k] = A[i];
    if(index > k)
    {
    k++;
    }
    }
    return ans;
    }