2
public int countDistinct(int[] nums, int k, int p) {4
// we are storing hashcode for all the substrings so that we can compare them faster.5
// main goal is to avoid entire sub array comparision using hashcode.6
Set<Long> ways = new HashSet<>();7
for (int i = 0; i < n; i++) {9
long hc = 1; // this is the running hashcode for sub array [i...j]10
for (int j = i; j < n; j++) {14
j]; // updating running hashcode, since we nums are <=200, we shall consider a15
// prime near 200 to avoid collision16
if (nums[j] % p == 0) cnt++;17
if (cnt <= k) { // if current subarray [i...j] is valid, add its hashcode in our storage.