1 / 5
Oct 2018

Hi, I am trying to solve this problem but keep on getting NZEC. Can somebody please help here

My Approach.
Trying to get the count of each char in both the strings. Then dividing length of one char in string_b with char, if present, in string_a. The quotient will be the number of string_b which can be made. Trying to get the minimum. (Assumption is one cannot use the char twice)

from collections import Counter
t = int(input())
for j in range(t):

n = input()
string_a = input()
string_b = input()

count_a = dict(Counter(string_a))
count_b = dict(Counter(string_b))

try:
	minimum = count_a[string_b[0]] // count_b[string_b[0]]
	for i in range(1,len(string_b)):
		value = count_a[string_b[i]] // count_b[string_b[i]]
		if value < minimum:
			minimum = value
	print(minimum)
except:
	print(0)
  • created

    Oct '18
  • last reply

    Oct '18
  • 4

    replies

  • 959

    views

  • 2

    users

  • 1

    link

@simes hey thanks for the reply… yes the output would be zero right… did that, its correct for that test case.

Problem URL - https://www.spoj.com/problems/AGPC01D/3

Also can you help with this test case

1
10 8
aaaaaaaaaa
aaaaaaaa

Since i am assuming, correct me if i am wrong, that you cannot use the char twice.
so for above case the output should be 1 right ??

The output should be zero for that test case I gave, but when I run your code in ideone, it gives a runtime error, i.e. this would be the NZEC you’re looking for.

Yes 1, for your test case.

@simes my bad there were indentation…but now its giving wrong answer error… i’ll have to figure out a test case for which this code fails…thanks