Find First Repeated Character in a String

Given a string 'STR' composed of lowercase English letters, identify the character that repeats first in terms of its initial occurrence.

Example:

Input:
STR = "abccba"
Output:
"a"
Explanation:

Although the first repeating character is 'c', the character 'a' is the first repeated character by initial appearance.

Constraints:

  • 1 <= T <= 200
  • 0 <= length of S <= 10000
  • ‘S’ consists of lowercase English alphabets.

In the scenario where no repeated character exists, output '%'.

Note:

Ensure that you return the repeated character that appears first, rather than simply the first character that repeats. If there are no repeating characters, return '%'. The function to implement is called “repeatedCharacter”.

AnswerBot
4mo

Find the first repeated character in a given string of lowercase English letters.

  • Iterate through the string and keep track of characters seen so far

  • Return the first character that repeats, if none, re...read more

Help your peers!
Select
Add answer anonymously...

Tredence Software Engineer interview questions & answers

A Software Engineer was asked Q. Explain the CSS box model.
A Software Engineer was asked Q. How do you change the background color of the first list item to yellow using jQ...read more
A Software Engineer was asked Q. How do you change all element background colors to blue using jQuery?

Popular interview questions of Software Engineer

A Software Engineer was asked Q1. Explain the CSS box model.
A Software Engineer was asked Q2. How do you change the background color of the first list item to yellow using jQ...read more
A Software Engineer was asked Q3. How do you change all element background colors to blue using jQuery?
Tredence Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits