My issue
t = int(input()) # Number of test cases
for i in range(t):
s = input() # String representing the jewels needed
count = 0
dictt = {}
# Count the frequency of each jewel
for char in s:
if char in dictt:
dictt[char] += 1
else:
dictt[char] = 1
# Calculate the minimum cost
for value in dictt.values():
count += (value + 1) // 2 # Corrected logic
print(count)
why test case are failing
My code
t = int(input()) # Number of test cases
for i in range(t):
s = input() # String representing the jewels needed
count = 0
dictt = {}
# Count the frequency of each jewel
for char in s:
if char in dictt:
dictt[char] += 1
else:
dictt[char] = 1
# Calculate the minimum cost
for value in dictt.values():
count += (value + 1) // 2 # Corrected logic
print(count)
Problem Link: Buy1-Get1 Practice Coding Problem