Skip to content

Latest commit

 

History

History
70 lines (64 loc) · 4.12 KB

24-string-exercise.md

File metadata and controls

70 lines (64 loc) · 4.12 KB

String Exercise

Easy:

  1. Write a program to reverse a string.
  2. Check if a given string is a palindrome.
  3. Count the number of vowels in a string.
  4. Convert a string to uppercase.
  5. Convert a string to lowercase.
  6. Find the length of a string without using the built-in length property.
  7. Remove all spaces from a string.
  8. Concatenate two strings without using the + operator.
  9. Find the first non-repeated character in a string.
  10. Replace all occurrences of a substring with another substring in a given string.
  11. Remove all occurrences of a specified character from a string.
  12. Check if a string starts with a specific substring.
  13. Check if a string ends with a specific substring.
  14. Count the number of words in a sentence.
  15. Remove duplicate characters from a string.
  16. Convert a sentence to title case (capitalize the first letter of each word).
  17. Swap the case of each character in a string (e.g., 'Hello' becomes 'hELLO').
  18. Find the most frequent character in a string.
  19. Implement a function to truncate a string if it's longer than a certain length, adding "..." at the end.
  20. Check if a string is a valid URL.

Medium:

  1. Implement a function to check if two strings are anagrams.
  2. Check if a string contains only digits.
  3. Count the occurrences of a specific word in a paragraph.
  4. Reverse the order of words in a sentence.
  5. Capitalize the first letter of each word in a sentence.
  6. Find the longest substring without repeating characters.
  7. Rotate a string to the left by a given number of positions.
  8. Check if a string is a valid email address.
  9. Implement a function to perform string compression (e.g., "aabcccccaaa" becomes "a2b1c5a3").
  10. Calculate the Levenshtein distance between two strings.
  11. Implement a function to convert a string to camel case.
  12. Check if a string is a valid IPv4 address.
  13. Reverse the order of words and the characters within each word in a sentence.
  14. Write a program to remove all HTML tags from a string.
  15. Implement a function to encode a string using Run-Length Encoding (e.g., "aaabbbbbcc" becomes "a3b5c2").
  16. Find the longest common prefix of an array of strings.
  17. Implement a function to decode a Run-Length Encoded string.
  18. Implement a function to perform base64 encoding and decoding.
  19. Check if a string contains a valid date in a specific format (e.g., "MM/DD/YYYY").
  20. Implement a function to convert a string to "snake_case".

Tough:

  1. Implement the indexOf function without using the built-in method.
  2. Find the longest palindrome substring in a given string.
  3. Implement regular expression matching for a simple pattern (e.g., ".ab" matches "aaaab").
  4. Write a program to reverse words in a sentence while preserving whitespace.
  5. Implement a function to perform basic string parsing similar to a compiler's lexer.
  6. Count the number of distinct substrings in a string.
  7. Implement the split function without using the built-in method.
  8. Write a program to generate all possible permutations of a string.
  9. Implement a function to calculate the edit distance between two strings.
  10. Find the shortest superstring that contains all given strings as substrings.
  11. Implement a function to reverse words in a sentence, while keeping the words' relative order unchanged (e.g., "The quick brown fox" becomes "ehT kciuq nworb xof").
  12. Implement a function to find the longest substring with at most K distinct characters.
  13. Write a program to format a multi-line text into a paragraph (word wrapping).
  14. Check if a given string follows a specific pattern (e.g., "abab" matches "redblueredblue").
  15. Implement a function to find the shortest palindrome that can be formed by adding characters to the end of a given string.
  16. Count the number of anagrams of a given word in a list of words.
  17. Implement a function to find the minimum window in a string that contains all characters of another string.
  18. Check if a string is a valid Roman numeral.
  19. Write a program to generate all valid IP addresses from a given string containing digits.
  20. Implement a function to reverse the order of words in a sentence, while preserving the spaces and punctuation.