Diagonal Traversal

My doubt is test cases failed in this code
Can u help me to find whts the error?

import java.util.*;
public class Main {
public static void main (String args[]) {

}
    
public static int[] FindDiagonalOrder(int[][] mat)
{
    int n=mat.length;
    int m=mat[0].length;
    int[] ans=new int [n*m];
    int i=0;
    for(int d=0;d<n+m-1;d++)
    {
    int r=0;
    int c=0;
        if(d<m)
        {
              r=0;
              c=d;
        }
        else
        {
           r=d-m+1;
           c=m-1; 
        } 
        ArrayList<Integer> list=new ArrayList<>();
        while(r<n && c>=0)
        {
            list.add(mat[r][c]);
            r++;
            c--;
        }
        if(d%2==0)
        {
            Collections.reverse(list);
        }
        for(int val:list)
        {
            ans[i]=val;
            i++;
        }

    }
    return ans;

}

}

@himanshimittal42_845cf80099683334 Please send me your full code bcoz their is nothing in the main function of this code.