My issue
what’s the problem with this code bro? @dpcoder_007
My code
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef {
public static void main(String[] args) throws java.lang.Exception {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while (t-- > 0) {
int n = scn.nextInt();
scn.nextLine(); // Consume newline character
String st = scn.nextLine();
long ans = ((long) n * (n + 1)) / 2;
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
HashMap<Character, Integer> hm = new HashMap<>();
String st1 = st.substring(i, j + 1);
for (int k = 0; k < st1.length(); k++) {
char c = st1.charAt(k);
hm.put(c, hm.getOrDefault(c, 0) + 1);
}
if (hm.getOrDefault('1', 0) == hm.getOrDefault('0', 0)) {
count++;
}
}
}
System.out.println(ans + count);
}
scn.close();
}
}
Problem Link: Sum of Modes Practice Coding Problem