Print each character and its frequency in sorted order
- We use the ASCII value of the character and build hashtable based on array index and store the counts there
# Define the string
str = "geeksforgeeks"
# Initialize the count array
count = [0]*26
# Loop through each character in the string and update the count array
for i in range(len(str)):
count[ord(str[i]) - ord('a')] += 1
# Loop through the count array and print the character and its count
for i in range(26):
if count[i] > 0:
print(chr(i + ord('a')), count[i])