Remove Consecutive Duplicates from String
Given a string STR
consisting of both lower and upper case characters, your task is to remove consecutive duplicate characters and return the newly formed string.
Input:
'STR' as a string, containing no spaces.
Output:
The modified string with consecutive duplicates removed.
Example:
Input:
'aaaAAbbcccbd'
Output:
'aAbcbd'
Constraints:
- 1 <= |STR| <= 105
- Time limit: 1 second
Note:
No need to print anything; simply implement the function as described.
AnswerBot
1y
The task is to remove consecutive duplicate characters from a given string and return the new string.
Iterate through the characters of the string
Compare each character with the next character
If they a...read more
Help your peers!
Add answer anonymously...
Popular interview questions of SDE-2
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app