anshu2002's blog

By anshu2002, history, 13 months ago, In English
class Solution{
    int solve(int i,int arr[],vector<int>& dp)
            return 0;
            return dp[i];
        int ans=1000001;
        for(int k=1;k<=arr[i-1] && i-k>=1;k++)
        return dp[i]=ans;
    int minJumps(int arr[], int n){
        int ans=solve(n,arr,dp);
        return ans;

I was solving the problem of minimum number of jumps to reach to the end of an array in geeksforgeeks Problem link

And this was my solution to it is right at the top

At worst , this should show TLE , but showing Segmentation fault . Can someone identify where am I wrong

  • Vote: I like it
  • +7
  • Vote: I do not like it

| Write comment?
13 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Maybe your code exceeds the stack limit of gfg. You can see this and this blogs related to the same problem.

13 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Every time when you call method "solve", you make a copy of ur array arr[] annd give it to parameter. You can give pointer of this array instead of making copy