Problem title
Difficulty
Avg time to solve

Rearrange Linked List
Moderate
22 mins
Algorithm to find best insert position in sorted array
Easy
10 mins
Jump Game
Moderate
15 mins
Remove Consecutive Duplicates
Easy
--
Funny Divisors
Easy
15 mins
Convert BST to Min Heap
Moderate
25 mins
Shortest Substring with all characters
Easy
--
Min Steps to one
Easy
15 mins
Fractional Knapsack
Easy
15 mins
Roman Numeral To Integer
Easy
15 mins
16

Remove Consecutive Duplicates From String

Difficulty: MEDIUM
Contributed By
Avg. time to solve
22 min

Problem Statement

You are given a string 'STR' consisting of lower and upper case characters. You need to remove the consecutive duplicates characters, and return the new string.

Example :
For a given string, "aaaAAbbcccbd"

The new string formed after removing the consecutive duplicates characters will be, "aAbcbd".
Input Format :
The first and the only line of input contains a string 'STR' with no space in between the characters.
Output Format :
Print the final string after removing all the consecutive duplicates.
Note :
You don't have to print anything, it has already been taken care of. Just implement the given function.
Constraints :
1 <= |S| <= 10^5

Where |S| represents the length of the string.

Time limit: 1 sec
Sample Input 1 :
aabccba
Sample Output 1 :
abcba
Explanation of Sample Output 1 :
The string basically is a concatenation of [aa][b][cc][b][a] without considering the brackets. From each segment we need to choose only 1 character as all the characters are duplicates, therefore the final answer is [a][b][c][b][a] = abcba
Sample Input 2 :
xxxyyyzwwzzz
Sample Output 2 :
xyzwz
Explanation of Sample Output 2 :
The string basically is a concatenation of [xxx][yyy][z][ww][zzz]. After choosing 1 character from each segment our final answer is [x][y][z][w][z] = xyzwz
Reset Code
Full screen
copy-code
Console