satisfies almost all test cases but still shows wrong answer

problem: link text
my submission: link text

i tried all the possible cases on my local ide and it works fine but shows wrong answer in codechef. Can anybody help me out here?

Check your code fr sample input. You are doing a silly error. Ping me if you arent able to catch it.

Anyways, here they are-

  1. Not resetting frequency array after every T
  2. Not taking new array of cost at every T. You are taking it only once, outside the loop. You have to take it T times as there are T separate arrays for cost of T different strings.
  3. Why use malloc? You can easily use char array in C.
  4. No need to test constraints. Its unnecessary trouble you’re taking.
1 Like

Hey @prince90,

  • The values of the array can be different as well since you are taking input only once in the array.
  • for every test case your code isn’t taking the cost array.
  • few other errors.

Here is a code snippet, which you can try or take help from.


int a[30]={0};

for(int i=0;i<26;i++){

cin >> a[i];

string str;

cin >> str;

int b[30]={0};
for(int i=0;i<str.length();i++){
int ans = 0;

for(int i=0;i<26;i++){
if(b[i] == 0){



  cout << ans << "\n"; 	}

Hope this helps!

He further isnt resetting the frequency array as well. :stuck_out_tongue: