Solution For Step 3 and Step 4 - First Set of Problems
Solution For Step 3 and Step 4 - First Set of Problems
Invalid
hat is a String? - A String is a sequence of Characters.
hat are characters? - can be any symbol on your keyboard. digits, alphabets, special characters
hat is a Palindrome? - A string of characters is a palindrome if the character sequence is same whether we read from right to le
Step 3: Solution
Get the input String, let's call it S1
If length of input String is greater than 100, print "Invalid Input" and End program
If String is empty or has a single character, print "Yes" and End program
Remove all spaces from S1
Create a new String called S2 by reversing the String S1 E.g. If S1 = "abc", S2 = "cba"
Starting comparing one letter at a time from left to right, between S1 and S2
6a. If any character doesn't match, print "No" and End Program
6b. Else continue with next character comparison
Print "Yes" and End Program
, S2 = "cba"
Problem: Check if a given year is a leap year A year is a leap year if - EITHER the year is multi
Step 1 - Understand the Problem
Is there any term in the problem that you don't understand? Read and underst 1
See if you can explain this clearly to a 10 year old 2
3
Step 2 - Design Test Data/Test Cases (Input and Expected Output) 4
Assumptions, Constraints & Questions
1 Year should be a whole number
2 BC years is invalid input, only AD will be considered 5
Invalid
String with no repeating letters is an isogram i.e. each character appears maximum once.
Step 3: Solution
Get the input String, let's call it S
If length of input String is greater than 100, print "Invalid Input" and End program
If String is empty or has a single character, print "Yes" and End program
Remove all spaces from S
Create one container where you can keep track of all characters seen so far, as we go through the String character
Repeat the below 2 steps for each character in S, from left to right
6a. Check if that character is already there in the container. If it is there, then print "No" and End Program
6b. Else add this character to the container and Continue with next character
Print "Yes" and End Program
d End Program
Problem: Find the number of times each character is repeated in a string For the given string, we will take each uniqu
Step 1 - Understand the Problem
Is there any term in the problem that you don't understand? Read and underst 1
See if you can explain this clearly to a 10 year old 2
3
Step 2 - Design Test Data/Test Cases (Input and Expected Output) 4
Assumptions, Constraints & Questions 5
1 String can include any character on keyboard 6
2 Space will be ignored
3 Empty string will result in no output (there is no character to count)
4 Captial letters and small letters will be treated as different cha 7
5 Maximum string length is 100
Valid
String length > 100 "Invalid input"
Invalid
r the given string, we will take each unique charcter in the string and see how many times its repeated and print count for each
Step 3: Solution
Get the input String, let's call it S
If length of input String is greater than 100, print "Invalid Input" and End program
If String is empty print no output and End program
Remove
how many alltimes
spaces from
it has S
occured so far, as we go through the String character by character, from left to
right. Initially this container will be empty.
Repeat the below 2 steps for each character in S, from left to right
6a. Check if that character is already there in the container. If it is there, increase its occurrence count by 1
6b. Else add this character to the container and initialize its Occurrence count to 1. Continue with next character
For each character stored in the container, print the Character and its Occurrence Count and End Program
Works
A year is a leap year if - EITHER the year is multiple of 400 OR the year is a multiple of 4 and not multiple of 100
Works
Works
Works
Works
Works
print count for each unique character
count by 1
h next character
nd Program