- Read the question carefully (twice).
- Break the task into the smallest steps.
- Sketch or write pseudocode before coding.
- Start small — test as you go.
- Check your solution with different cases.
Problem Statement
Write a program that finds the first recurring letter in a string.
A recurring letter is a letter that appears more than once in the string.
The program should return the first letter that repeats. If no letter repeats, the program should return "No recurring letters found".
Instructions
- Input: Your program should take a string (a sequence of characters).
- Example:
"computerprogramming"
- Example:
- Process:
- Scan through the string letter by letter.
- Keep track of the letters you have already seen.
- As soon as you find a letter that you have already seen, stop.
- Output: Print the first recurring letter OR
"No recurring letters found"if none exists.
Example Runs
Example 1:
Input:
computerprogramming
Output:
p
Explanation: "p" is the first recurring letter. It appears at positions 3 and 9.
Example 2:
Input:
abcdefg
Output:
No recurring letters found
Explanation: All letters are unique.
Example 3:
Input:
swiss
Output:
s
Explanation: "s" is the first recurring letter. It appears at positions 0 and 3.
Testing Your Program
Try these additional inputs:
"banana"→ should return"a""apple"→ should return"p""xyz"→ should return"No recurring letters found""mississippi"→ should return"i"
Success Criteria
- Program correctly identifies the first recurring letter.
- Program handles strings with no recurring letters.
- Program works with both short and long strings.
- Program output matches the examples.