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”.

Be the first one to answer
Add answer anonymously...
Borderfree Mern Stack Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter