NOPAL2 Editorial

public static void solve()throws IOException {
int n = ri();
char s[] = rac();
HashMap<Character , Integer>map = new HashMap<>();
for(char ch : s) {
map.put(ch , map.getOrDefault(ch,0) + 1);
}
// _ _ _
List list = new ArrayList<>(map.keySet());
Collections.sort(list,(a,b)-> map.get(b)-map.get(a));
char ans[] = new char[n];
Arrays.fill(ans , ‘-’);
TreeSet set = new TreeSet<>();
for(int i =0;i < n;i++) {
set.add(i);
}
for(char ch : list) {
int cnt = map.get(ch);
if(set.size() == 0) {
System.out.println(“NO”);
return ;
}
int index = set.first();
while(cnt > 0) {
if(index >= n) {
System.out.println(“NO”);
return ;
}
ans[index] = ch;
set.remove(index);
index+=3;
cnt–;

                }
                
            }
            System.out.println("YES");
            System.out.println(new String(ans));

        }

Can someone please tell me for which test case my code is not working

i am getting the same results as yours for the test cases , could’nt figure out for what test cases the logic fails, even i am waiting for some one to reply with proper ans.

check out for this test case once the ans is YES & abcdabcd.
1
8
abcdabcd

check this out once the ans is YES & abcdabcd.
1
8
abcdabcd

Why is the order of containers c3 → c2 → c1 and not c1->c2->c3 ??? Can anyone please explain?

Can you help me out with finding a testcase where my code fails.
while submitting only one testcase (subtask 4) fails and I m not able to figure it out.

here is my submission: CodeChef: Practical coding for everyone
will be really grateful if u kindly look into this !!

Really Helpful and clear approach :+1:…thanks dude.