Challenge 1: Basic Data Manipulation
Problem:
Write a program to calculate the frequency of each character in a given string (case-insensitive) and display the results in alphabetical order. Ignore spaces and special characters.
Requirements:
- The program should take a string as input from the user.
- Count each letter's frequency.
- Display the output in alphabetical order (e.g., A: 3, B: 1, ...).
Example Input:
"Hello, World!"
Expected Output:
D: 1
E: 1
H: 1
L: 3
O: 2
R: 1
W: 1
Challenge 2: Reverse Words in a Sentence
Objective:
Write a C# program that reverses the words in a sentence while maintaining the original word order and sentence structure.
Input:
"Hello World! How are you?"
Output:
"you? are How World! Hello"
Requirements:
- The user will provide a sentence (could include punctuation, spaces, etc.).
- Return the sentence with each word reversed but the order of the words maintained.
Considerations:
- You should not reverse the letters in the words; only the order of the words should be reversed.
- Handle punctuation and spaces properly (they should stay attached to the word they belong to).
Example Test Cases:
Input: "Coding is fun!"
Output: "fun! is Coding"
Challenge 3: Check for Palindromes in a Sentence
Problem:
Write a C# program that takes a sentence as input and identifies all the words that are palindromes.
A palindrome is a word that reads the same backward as forward (e.g., "radar", "level").
Requirements:
- Ignore case sensitivity (e.g., "Radar" should be treated as a palindrome).
- Ignore punctuation and spaces in the input.
- Identify and output all the palindromic words in the sentence.
- If no palindromes exist, notify the user.
- Avoid duplicate palindrome results in the output.
Example Input:
Enter a sentence: "Madam Arora teaches malayalam and a radar is nearby."
Expected Output:
Palindromes found: Madam, Arora, malayalam, radar
Challenge 4: Anagram Detector
Problem:
Write a C# program that takes two strings as input and checks if they are anagrams of each other.
Definition of an Anagram: Two strings are anagrams if they contain the same characters in the same frequency, but possibly in a different order.
Requirements:
- Ignore spaces and case differences while comparing the strings.
- Check if both strings contain exactly the same characters with the same frequency.
Example Input:
String 1: "Listen"
String 2: "Silent"
Expected Output:
The strings are anagrams.
Challenge 5: Count Vowels and Consonants in a String
Problem:
Write a C# program that counts the number of vowels and consonants in a given string. Ignore spaces, punctuation, and other non-alphabetic characters. Your program should print the total count of vowels and consonants separately.
Input:
A sentence entered by the user.
Example Input: "Hello, world!"
Output:
Total Vowels: 3
Total Consonants: 7
Requirements:
- Create a method to count vowels and consonants in the string.
- Use a
foreach
loop to iterate through each character.
- Make the program case-insensitive.
- Output the results to the console.
Challenge 6: Number Pyramid
Problem:
Write a C# program that prints a number pyramid with a given number of rows. The pyramid should be symmetrical and made of numbers.
Input:
The user provides the number of rows for the pyramid.
Example Input: 5
Output:
1
121
12321
1234321
123454321
Requirements:
- Each row should have an increasing sequence of numbers followed by a decreasing sequence.
- The pyramid should be properly aligned (use spaces to center the numbers).
Challenge 7: Find the Missing Number in an Array
Problem:
You are given an array of distinct numbers taken from a range. The array contains numbers from a
to b
, but one number is missing. Your task is to find the missing number in this range. The range can start from any number, not necessarily 1.
Approach:
We can use the sum formula for an arithmetic sequence to efficiently find the missing number. The sum of numbers from a
to b
is given by the formula:
Sum(a, b) = (b - a + 1) × (a + b) / 2
Steps:
- Calculate the expected sum of the range from
a
to b
using the formula.
- Calculate the actual sum of the numbers in the array.
- The missing number is the difference between the expected sum and the actual sum.
Example:
Given the array: [3, 4, 5, 7, 8]
Range: 3 to 8
Missing number: 6
1. Calculate the expected sum:
Sum(3, 8) = (8 - 3 + 1) × (3 + 8) / 2 = 6 × 11 / 2 = 33
2. Calculate the actual sum of the array:
3 + 4 + 5 + 7 + 8 = 27
3. The missing number:
Missing = 33 - 27 = 6
Requirements:
- Input: An array of distinct numbers and the range (
a
to b
).
- Output: The missing number in the array.
Challenge 8: Find and Display Missing Numbers in a Sequence
Problem:
You are given a sequence of integers that should form a continuous sequence without gaps. However, some numbers may be missing from the sequence. Your task is to identify and display all the missing numbers.
Requirements:
- Input: A comma-separated list of integers (can be in any order).
- Output: A list of missing numbers, or "No missing numbers" if none are missing.
- Handle edge cases where no numbers are missing.
- Efficiently identify missing numbers without brute force.
Steps:
- Parse the input to extract integers from the list.
- Find the minimum and maximum numbers in the sequence.
- Generate the full range of numbers from the minimum to the maximum.
- Compare the generated range with the input sequence to find missing numbers.
- Output the missing numbers or print "No missing numbers" if the sequence is complete.
Example:
Input: 1, 2, 4, 5, 7, 9
Output: The missing numbers are: 3, 6, 8
Input: 1, 2, 3, 4, 5
Output: No missing numbers
Input: 18, 12, 13, 15, 16
Output: The missing numbers are: 11, 14
Challenge 9: Find the Most Frequent Character
Problem:
Write a program to find the most frequently occurring character in a given string. If there is a tie (two or more characters appear the same maximum number of times), return any one of them.
Requirements:
- Input: A string entered by the user (e.g., "characteristics").
- Output: The most frequent character in the string.
- Ignore spaces (they shouldn't be counted).
- Consider case sensitivity (e.g., 'A' and 'a' are different characters).
Steps:
- Parse the string to count the occurrences of each character.
- Ignore spaces when counting characters.
- Check the frequency of each character and determine the one with the highest frequency.
- If multiple characters have the same frequency, return any one of them.
- Output the most frequent character.
Example:
Input: "characteristics"
Output: The most frequent character is: 'c'
Challenge 10: Multifaceted Puzzle - Character Analysis and Sequence Finder
Problem:
Write a program that analyzes a given string and performs the following:
1. Character Frequency Analysis:
Identify the top 3 most frequently occurring characters (case-insensitive). If two characters have the same frequency, prioritize lexicographically smaller characters (e.g., 'a' over 'b').
2. Longest Consecutive Sequence:
Find the longest consecutive sequence of any character (e.g., "aaabbcccaaa" has a sequence of "aaa" with a length of 3).
3. Generate a New String:
Construct a new string that contains:
- The top 3 characters from step 1, each repeated by their frequency.
- The longest sequence from step 2 appended to the end.
Requirements:
- Input: A string entered by the user (e.g., "aaabbcccaaadddeefff").
- Output: A string with:
- The top 3 most frequent characters.
- The longest consecutive sequence of any character.
Steps:
- Parse the string and analyze the frequency of each character.
- Identify the top 3 most frequent characters, resolving ties lexicographically.
- Find the longest consecutive sequence of any character in the string.
- Construct a new string based on the top 3 characters and the longest consecutive sequence.
Example:
Input: "aaabbcccaaadddeefff"
Output:
Top 3 characters:
a: 6
c: 3
f: 3
Longest consecutive sequence: aaa (length: 3)
Generated string: aaaaaacccfffaaa