Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Remove Consecutive Duplicates
EASY
39 upvotes
Strings
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Strings
-
-
Other topics
Problem solved
Badge
Skill meter
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Remove Consecutive Duplicates

Contributed by
Sobhagya Singh
Easy
yellow-spark
0/40
Share
39 upvotes

Problem Statement

You are given a string ‘str’ of size ‘N’. Your task is to remove consecutive duplicates from this string recursively.

For example:

If the input string is ‘str’ = ”aazbbby”, then your output will be “azby”.
Note that we are just removing adjacent duplicates.
Detailed explanation ( Input/output format, Notes, Constraints, Images )

Sample Input 1:

2
7
aazbbby
6
aabbcb

Sample Output 1:

azby
abcb

Explanation of Sample Input 1:

Test Case 1:

Given ‘str' = ”aazbbby”
After removing adjacent duplicates string will be “azby”

Test Case 2:

Given ‘str’ = “aabbcb”
After removing adjacent duplicates string will be “abcb”

Sample Input 2:

2
5
abcde
5
aaaaa

Sample Output 2:

abcde
a

Explanation of Sample Input 2:

Test Case 1:

Given ‘str' = ”abcde”
There are no duplicates in the input string so the final string will be “abcde” 

Test Case 2:

Given ‘str’ = “aaaaa”
After removing adjacent duplicates string will be “a”
Reset Code
Full screen
Auto
copy-code
Console