-3

First recurring letter Problem Submissions Leaderboard Discussions Given a string, return the first recurring letter of that string. If there are no recurring letters, return “None”.

Input Format

The input line contains a string Constraints

The string length should be bigger than 2 The string should not contain whitespaces Output Format

Return the recurring letter or “None”


Sample Input 0

life

Sample Output 0

None

Explanation 0

In the word life there is no recurring letter, so the output should be None


Sample Input 1

gjirafa

Sample Output 1

a

Explanation 1

The first recurring letter in the string gjirafa is a


Sample Input 2

statistics

Sample Output 2

t

Explanation 2

The first recurring letter in the string statistics is t


Sample Input 3

work

Sample Output 3

None



         
azro
  • 53,056
  • 7
  • 34
  • 70
  • 4
    Welcome to Stack Overflow! You seem to be asking for someone to write some code for you. Stack Overflow is a question and answer site, not a code-writing service. Please [see here](https://stackoverflow.com/help/how-to-ask) to learn how to write effective questions – azro Apr 10 '22 at 08:05
  • We don't do your homework. And surely when you don't even ask and juste paste **your** assignment – azro Apr 10 '22 at 08:06

1 Answers1

0

For this code to work, you will need to split the word into its individual letters, which are stored into a String array word[n], where n is the number of letters in the word. This can be done using a for loop and split function.

READ: Splitting words into letters in Java

After that, you need to check each letter manually using two for loops.

for (i=0;i<=n;i++)
{
temp1=word[i];
for(j=i+1;j<=n;j++)
  {
    if(temp1.equals(word[j]))
    {
       System.out.println(word[i]);
       temp2="Yes";
    }
  }
}
if(temp2.equals("Yes")
{

}
else
{
System.out.println("None");
}

Next time, I would recommend that you provide at-least part of what you have tried so that we can help. Asking a question without providing code isn't good practice and should be avoided.