Https://ide.codingblocks.com/s/260642

its giving runtime error

saying heap space has fulled

but sir also has did same in video , has passed all cases

This is link of problem below

https://hack.codingblocks.com/app/contests/1108/281/problem

Pls share ur code link.

sir upr diya toh hai

Your code is showing error.

yup code is showing runtime error

import java.util.*; public class Main { public static void main(String args[]) { Scanner s=new Scanner(System.in); int n=s.nextInt(); int m=s.nextInt(); long arr1[]=new long[5005]; long arr2[]=new long[5005]; for(int i=0;i<n;i++) arr1[i]=s.nextLong(); Arrays.sort(arr1); for(int i=0;i<m;i++) arr2[i]=s.nextLong(); Arrays.sort(arr2); long dp[][]=new long[5005][5005]; for(int i=0;i<5005;i++){ for(int j=0;j<5005;j++){ dp[i][j]=-1; } } long ans=solve(arr1,arr2,n,m,dp,0,0); System.out.println(ans); } public static long solve(long[] arr1,long[] arr2,int n,int m,long[][] dp,int i,int j){ if(i==n){ return 0; } if(j==m){ return Long.MAX_VALUE; } if(dp[i][j]!=-1){ return dp[i][j]; } long op1 = Math.abs(arr1[i]-arr2[j]) + solve(arr1,arr2,n,m,dp,i+1,j+1) ; long op2 = solve(arr1,arr2,n,m,dp,i,j+1); dp[i][j]=Math.min(op1,op2); return dp[i][j]; } }

here it is , if you are getting problem in accessing the code