🔤 String Manipulation¶
Strings are sequences of characters. From simple name printing to complex text processing, mastering strings is vital. These problems will help you understand ASCII values, character arrays, and built-in string methods.
1. String Length¶
Rating: Beginner | Difficulty: Easy
Input a string and find its length (without using built-in functions like strlen() or
.length()). 💡 Hint
Loop until you hit the null terminator \0 (in C)
or until the end of the character array.
2. Concatenate Two Strings¶
Rating: Beginner | Difficulty: Easy
Join two strings together to form a single string. 💡 Hint
Create a
larger array and copy characters from the first string, then the second.
3. String Reversal¶
Rating: Beginner | Difficulty: Easy
Print a string in reverse order. 💡 Hint
Loop from length - 1 down to
0.
4. Check Palindrome String¶
Rating: Beginner | Difficulty: Easy
Check if a string is a palindrome (e.g., "madam", "racecar"). 💡 Hint
Compare characters from the start and end moving inwards.
5. Count Vowels and Consonants¶
Rating: Beginner | Difficulty: Easy
Count how many vowels and consonants are in a given string. 💡 Hint
Use
if to check if a character is in a, e, i, o, u.
6. Toggle Case¶
Rating: Intermediate | Difficulty: Medium
Convert all lowercase characters to uppercase and vice versa in a string. 💡
Hint
Lowercase 'a' is 97 and Uppercase 'A' is 65. The difference is 32.
7. String Comparison¶
Rating: Beginner | Difficulty: Easy
Compare two strings to see if they are identical (without using strcmp() or .equals()).
💡 Hint
Check if lengths match first, then compare character by character.8. Remove All Spaces¶
Rating: Intermediate | Difficulty: Medium
Input a sentence and remove all blank spaces from it. 💡 Hint
Copy only
non-space characters into a new string.
9. Word Count¶
Rating: Intermediate | Difficulty: Medium
Count the total number of words in a sentence. 💡 Hint
Count the number
of spaces and add 1 (assuming single spaces between words).
10. Character Frequency¶
Rating: Advanced | Difficulty: Hard
Find the frequency of a specific character in a string. 💡 Hint
Loop
through the string and increment a counter whenever str[i] == ch.
11. Find Substring¶
Rating: Advanced | Difficulty: Hard
Check if a specific word (substring) exists within a larger sentence. 💡
Hint
Use a nested loop to compare the pattern with sections of the main string.
12. Replace Character¶
Rating: Intermediate | Difficulty: Medium Replace every occurrence of a specific character with another (e.g., replace 'a' with '@').
💡 Hint
`if (str[i] == target) str[i] = replacement;`13. Anagram Check¶
Rating: Advanced | Difficulty: Hard
Check if two strings are anagrams (contain the same characters in any order, e.g., "listen" and
"silent"). 💡 Hint
Sort both strings and then compare them.
14. First Non-Repeating Character¶
Rating: Pro | Difficulty: Medium
Find the first character in a string that does not repeat. 💡 Hint
Use a
frequency array (size 256 for ASCII) to count occurrences first.
15. Title Case Conversion¶
Rating: Intermediate | Difficulty: Medium
Convert a sentence to Title Case (capitalize the first letter of every word). 💡
Hint
Capitalize str[0] and any character that follows a space.