0% found this document useful (0 votes)
35 views14 pages

CC - String Tasks

The document outlines a series of string manipulation tasks, including reversing a string, counting vowels and consonants, checking for palindromes, and validating IP addresses. Each task includes a problem statement, sample input, and expected output, providing a comprehensive guide for programming exercises. The tasks range from basic string operations to more complex challenges like finding the longest palindromic substring and checking for balanced parentheses.

Uploaded by

er.arunscope
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views14 pages

CC - String Tasks

The document outlines a series of string manipulation tasks, including reversing a string, counting vowels and consonants, checking for palindromes, and validating IP addresses. Each task includes a problem statement, sample input, and expected output, providing a comprehensive guide for programming exercises. The tasks range from basic string operations to more complex challenges like finding the longest palindromic substring and checking for balanced parentheses.

Uploaded by

er.arunscope
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

✨ String Tasks ✨

1. Reverse a String

Problem: Write a Java program to reverse a given string.

Sample Input: "hello"

Sample Output: "olleh"

2. Count Vowels and Consonants

Problem: Find the number of vowels and consonants in a given string.

Sample Input: "programming"

Sample Output: Vowels: 3, Consonants: 8

3. Palindrome Check

Problem: Check if a given string is a palindrome (reads the same forward


and backward).

Valid Case:

Input: "madam"

Output: "Palindrome"

Invalid Cases:

Input: "hello"

Output: "Not a Palindrome"

Boundary Condition: Single character strings are always palindromes.

4. Remove Spaces from a String

Problem: Remove all spaces from a given string.

Sample Input: "Hello World"

Sample Output: "HelloWorld"

5. Count Words in a String

✨ String Tasks ✨ 1
Problem: Count the number of words in a given sentence.

Sample Input: "Welcome to coding world"

Sample Output: 4

6. Find First Non-Repeating Character

Problem: Find the first non-repeating character in a given string.

Sample Input: "aabbccde"

Sample Output: "d"

Invalid Case:

Input: "aabbcc"

Output: "No Non-Repeating Character Found"

7. Check Anagram

Problem: Write a program to check if two strings are anagrams of each


other.

Valid Case:

Input: "listen" , "silent"

Output: "Anagrams"

Invalid Case:

Input: "hello" , "world"

Output: "Not Anagrams"

Boundary Condition: Both strings should be of equal length.

8. Longest Word in a Sentence

Problem: Find the longest word in a given sentence.

Sample Input: "The quick brown fox jumps over the lazy dog"

Sample Output: "jumps"

9. Replace Vowels with ‘*’

Problem: Replace all vowels in a string with ‘*’.

✨ String Tasks ✨ 2
Sample Input: "banana"

Sample Output: "b*n*n*"

10. Find Substring Occurrence

Problem: Count how many times a given substring appears in a string.

Sample Input: "ababcabc" , Substring: "abc"

Sample Output: 2

1. Check for Valid IP Address

Problem: Write a program to check if a given string is a valid IPv4 address.

Valid Case:

Input: "192.168.1.1"

Output: "Valid IP"

Invalid Cases:

Input: "999.999.999.999"

Output: "Invalid IP (Octet value exceeds 255)"

Input: "192.168.1"

Output: "Invalid IP (Less than 4 octets)"

Input: "192.168.1.1.1"

Output: "Invalid IP (More than 4 octets)"

Input: "abc.def.ghi.jkl"

Output: "Invalid IP (Non-numeric values)"

Boundary Condition: Ensure each octet is between 0 and 255.

11. Convert String to Uppercase

Problem: Convert all characters of a given string to uppercase without using


built-in functions.

Sample Input: "hello world"

Sample Output: "HELLO WORLD"

✨ String Tasks ✨ 3
12. Find Character Frequency

Problem: Count the frequency of each character in a given string.

Sample Input: "apple"

Sample Output: a:1, p:2, l:1, e:1

13. Remove Duplicate Characters

Problem: Remove all duplicate characters from a string.

Sample Input: "programming"

Sample Output: "progamin"

14. Toggle Case of Characters

Problem: Convert all uppercase letters to lowercase and vice versa.

Sample Input: "HeLLo WoRLD"

Sample Output: "hEllO wOrld"

15. Find Longest Palindromic Substring

Problem: Find the longest substring in a given string that is a palindrome.

Sample Input: "babad"

Sample Output: "bab"

16. Count Occurrences of Each Word

Problem: Count how many times each word occurs in a sentence.

Sample Input: "apple banana apple orange banana"

Sample Output: apple: 2, banana: 2, orange: 1

17. Reverse Words in a Sentence

Problem: Reverse each word in a sentence while keeping the word order
intact.

Sample Input: "Hello World"

Sample Output: "olleH dlroW"

18. Check for Pangram

✨ String Tasks ✨ 4
Problem: Determine whether a given sentence contains every letter of the
alphabet at least once.

Sample Input: "The quick brown fox jumps over the lazy dog"

Sample Output: "Pangram"

19. Find All Substrings of a String

Problem: Generate and print all possible substrings of a given string.

Sample Input: "abc"

Sample Output: "a", "ab", "abc", "b", "bc", "c"

20. Convert a String to Title Case

Problem: Convert the first letter of each word in a string to uppercase.

Sample Input: "hello world"

Sample Output: "Hello World"

21. Remove All Digits from a String

Problem: Remove all numeric digits from a given string.

Sample Input: "abc123def456"

Sample Output: "abcdef"

22. Find Longest Word with Only Unique Characters

Problem: Find the longest word from a sentence containing only unique
characters.

Sample Input: "apple orange banana unique"

Sample Output: "unique"

23. Check if a String is a Valid Password

Problem: Validate a password based on these rules:

Minimum 8 characters

At least one uppercase letter

At least one lowercase letter

✨ String Tasks ✨ 5
At least one digit

At least one special character (@, #, $, %, &, *)

Valid Case:

Input: "P@ssw0rd123"

Output: "Valid Password"

Invalid Case:

Input: "password"

Output: "Invalid Password"

24. Find the Shortest Palindromic Substring

Problem: Find the shortest substring that forms a palindrome.

Sample Input: "abacdfgdcaba"

Sample Output: "aba"

25. Check for Balanced Parentheses

Problem: Write a program to check if a given string contains balanced


parentheses.

Valid Case:

Input: "(a+b)-(c*d)"

Output: "Balanced"

Invalid Case:

Input: "(a+b)*(c-d"

Output: "Not Balanced"

26. Find Common Characters Between Two Strings

Problem: Find all common characters between two given strings.

Sample Input: "banana" , "band"

Sample Output: "b, a, n"

27. Find All Possible Palindromic Substrings

✨ String Tasks ✨ 6
Problem: Print all possible palindromic substrings from a given string.

Sample Input: "abbaeae"

Sample Output: "a, b, b, a, bb, aba, e, ae, a, eae"

28. Calculate Lexicographical Rank of a String

Problem: Find the rank of a string in all its possible lexicographical


permutations.

Sample Input: "string"

Sample Output: 598

29. Check for String Interleaving

Problem: Check if a string is an interleaving of two other strings.

Valid Case:

Input: "abc", "def", "adbcef"

Output: "True"

Invalid Case:

Input: "abc", "def", "abdecf"

Output: "False"

30. Check for String Interleaving

Problem: Check if a string is an interleaving of two other strings.

Valid Case:

Input: "abc", "def", "adbcef"

Output: "True"

Invalid Case:

Input: "abc", "def", "abdecf"

Output: "False"

31. Convert String to Unicode/ASCII Values

Problem: Convert each character of a string to its corresponding ASCII value.

✨ String Tasks ✨ 7
Sample Input: "abc"

Sample Output: 97 98 99

32. Check if a String Contains Only Digits

Problem: Determine whether a given string contains only numeric digits.

Valid Case:

Input: "123456"

Output: "True"

Invalid Case:

Input: "123a56"

Output: "False"

33. Find the First Repeated Character

Problem: Find the first repeated character in a given string.

Sample Input: "programming"

Sample Output: "r"

34. Convert String to Integer

Problem: Convert a given numeric string to its integer equivalent.

Sample Input: "12345"

Sample Output: 12345

Invalid Case:

Input: "12a45"

Output: "Invalid Input"

35. Check if Two Strings Are Isomorphic

Problem: Determine whether two strings are isomorphic (character mapping is


consistent).

Valid Case:

Input: "egg", "add"

✨ String Tasks ✨ 8
Output: "True"

Invalid Case:

Input: "foo", "bar"

Output: "False"

36. Find Maximum Occurring Character

Problem: Find the character that appears the most times in a string.

Sample Input: "character"

Sample Output: "c"

37. Find All Permutations of a String

Problem: Generate and print all possible permutations of a given string.

Sample Input: "abc"

Sample Output: "abc, acb, bac, bca, cab, cba"

38. Check if String is a Rotation of Another

Problem: Check if one string is a rotation of another using a substring check.

Valid Case:

Input: "abcd", "cdab"

Output: "True"

Invalid Case:

Input: "abcd", "acbd"

Output: "False"

39. Print Duplicate Characters from a String

Problem: Print all duplicate characters from a string.

Sample Input: "programming"

Sample Output: "r, g, m"

40. Convert Sentence to Abbreviation

✨ String Tasks ✨ 9
Problem: Convert a sentence into its abbreviation using the first character of
each word.

Sample Input: "National Aeronautics and Space Administration"

Sample Output: "NASA"

41. Convert Sentence to Abbreviation

Problem: Convert a sentence into its abbreviation using the first character of
each word.

Sample Input: "National Aeronautics and Space Administration"

Sample Output: "NASA"

42. Find the Length of the Longest Substring Without Repeating Characters

Problem: Find the longest substring with all distinct characters.

Sample Input: "abcabcbb"

Sample Output: 3

43. Count the Number of Palindromic Substrings

Problem: Count all possible palindromic substrings within a string.

Sample Input: "abba"

Sample Output: 6

44. Find the First Non-Repeating Word in a Sentence

Problem: Identify the first word in a sentence that does not repeat.

Sample Input: "apple banana apple orange banana"

Sample Output: "orange"

45. Convert Roman Numerals to Integer

Problem: Convert a given Roman numeral to an integer.

Sample Input: "IX"

Sample Output: 9

46. Find Longest Common Prefix

✨ String Tasks ✨ 10
Problem: Find the longest common prefix among an array of strings.

Sample Input: ["flower", "flow", "flight"]

Sample Output: "fl"

47. Reverse Words in a String Without Using Extra Space

Problem: Reverse the order of words in a string without using extra space.

Sample Input: "The sky is blue"

Sample Output: "blue is sky The"

48. Find All Possible Encodings of a Numeric String

Problem: Given a string of digits, find all possible valid letter encodings (A=1,
B=2,... Z=26).

Sample Input: "12"

Sample Output: "AB, L"

49. Check if a String is a Subsequence of Another String

Problem: Check if one string is a subsequence of another.

Valid Case:

Input: "abc", "ahbgdc"

Output: "True"

Invalid Case:

Input: "axc", "ahbgdc"

Output: "False"

50. Calculate Minimum Operations to Make Two Strings Equal

Problem: Find the minimum number of operations required to make two given
strings identical.

Sample Input: "abcdef", "azced"

Sample Output: 3

51. Check for Balanced Parentheses

✨ String Tasks ✨ 11
Problem: Write a program to check if a given string contains balanced
parentheses.

Valid Case:

Input: "(a+b)-(c*d)"

Output: "Balanced"

Invalid Case:

Input: "(a+b)*(c-d"

Output: "Not Balanced"

52. Find the Most Frequent Word

Problem: Find the word that appears most frequently in a given sentence.

Sample Input: "apple orange apple banana orange apple"

Sample Output: "apple"

53. Sort Words in a String

Problem: Sort all the words in a given string in lexicographical order.

Sample Input: "banana apple mango"

Sample Output: "apple banana mango"

54. Find All Substrings of a String

Problem: Print all possible substrings of a given string.

Sample Input: "abc"

Sample Output: "a, ab, abc, b, bc, c"

55. Convert to Title Case

Problem: Convert a given sentence to title case, where the first letter of each
word is capitalized.

Sample Input: "hello world from java"

Sample Output: "Hello World From Java"

56. Remove Consecutive Duplicates

✨ String Tasks ✨ 12
Problem: Remove consecutive duplicate characters from a string.

Sample Input: "aabbccdee"

Sample Output: "abcde"

57. Check if Two Strings Are Rotation of Each Other

Problem: Check if one string is a rotation of another.

Valid Case:

Input: "abcd", "cdab"

Output: "True"

Invalid Case:

Input: "abcd", "acbd"

Output: "False"

58. Calculate Frequency of Each Character

Problem: Count the occurrence of each character in a string.

Sample Input: "banana"

Sample Output: { 'b': 1, 'a': 3, 'n': 2 }

59. Check for Pangram

Problem: Determine whether a given sentence contains every letter of the


English alphabet.

Valid Case:

Input: "The quick brown fox jumps over the lazy dog"

Output: "True"

Invalid Case:

Input: "Hello world"

Output: "False"

60. Count Number of Words in a String

Problem: Count the number of words in a given sentence.

✨ String Tasks ✨ 13
Sample Input: "Hello world from Java"

Sample Output: 4

61. Find the Largest Word in a Sentence

Problem: Find the word with the maximum length from a given sentence.

Sample Input: "I love programming in Java"

Sample Output: "programming"

62. Remove Consecutive Duplicates

Problem: Remove consecutive duplicate characters from a string.

Sample Input: "aabbccdee"

Sample Output: "abcde"

✨ String Tasks ✨ 14

You might also like