We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
# Count character frequency
for i in s:
if i in char_count:
char_count[i] += 1
else:
char_count[i] = 1
# Convert to list of tuples
stored_items = list(char_count.items())
# Manual sort by count descending
for i in range(len(stored_items)):
for j in range(i + 1, len(stored_items)):
if stored_items[i][1] < stored_items[j][1]:
stored_items[i], stored_items[j] = stored_items[j], stored_items[i]
# Print each char and count on a new line if count > 1
for item in stored_items:
if item[1] > 1:
print(item[0], item[1]) 5 test case fails out of 6
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Company Logo
You are viewing a single comment's thread. Return to all comments →
if name == 'main': s = input() char_count = {}