Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dshah1797/7393305a114abfa4175e015c8c8adf7d to your computer and use it in GitHub Desktop.
Save dshah1797/7393305a114abfa4175e015c8c8adf7d to your computer and use it in GitHub Desktop.
“Java solution for LeetCode 3343: Balanced Permutations with DFS & Memo”
import java.util.*;
class Solution {
private static final int MOD = 1_000_000_007;
private int n;
private int[] nums;
private long[][][] memo;
private long totalPermInv;
public int countBalancedPermutations(String num) {
// … your implementation …
}
private long dfs(int idx, int evenLeft, int oddLeft, int remSum) {
// … DFS + memoization …
}
private long computeDuplicatesFactorial(int[] A) {
// … factorial of duplicates …
}
private long modInverse(long a) {
// … Fermat’s little theorem …
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment