check out this solution if you want most simple yet significant solution in java[beats 100%]
IntuitionApproachComplexity
Time complexity:O(n)

Space complexity:O(1)
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int diagonalSum(int[][] mat) {
       int primarySum = 0;
    int secondarySum = 0;
    int n = mat.length;

    for (int i = 0; i < n; i++) {
        primarySum += mat[i][i]; // Primary diagonal
        secondarySum += mat[i][n - i - 1]; // Secondary diagonal
    }

    // If matrix size is odd, subtract the middle element (counted twice)
    if (n % 2 == 1) {
        secondarySum -= mat[n / 2][n / 2];
    }

    return primarySum + secondarySum;
    }
}
```

![WhatsApp Image 2025-01-05 at 23.05.57_6e91730f.jpg](https://assets.leetcode.com/users/images/9bc04218-65b2-40a5-ba64-9831dffc6fca_1736700185.0976753.jpeg)

['Array', 'Matrix', 'Java']