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”.
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
Top Tredence Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Reviews
Interviews
Salaries
Users/Month