Recursion Remove Duplicate String

I need to create the char array to check for the duplicate string. means that if check if the previous index element is same or not ?

@Vikaspal you have to check for consecutive duplicate characters, meaning that they should occur next to each other, for eg if a string is lalalalala then no changes are to be made. You can either check for the “next” character in the string, or the “prev” one depending on your approach. Just make sure you are referring to consecutive characters only.

@Ishitagambhir first i want to print those character which are occur more than one time Ex :
alllaba so output will be lll
. I am trying to do this iteratively first :
//Write a program that return the duplicate arrays

#include
using namespace std;

// Return that cout occur same
void stringcheck(char*in) {
int i,j;
for (i = 0; in[i] != ‘\0’; i++) {
int s = 0, e = 0;
for (j = i + 1; in[j] != ‘\0’; j++) {
// if (in[i] != in[j]) {
// break;
// }
if (in[i] == in[j]) {
s = i;
e = j; //set the start and the endpoistion
}

	}
	for (int k = s; k <= e; ++i)
		{
			cout << in[k];
		}

}

}

int main() {
char in[] = “hello”;
//int size = sizeof(in)/sizeof(char);
//cout << size;
stringcheck(in);

return 0;

}

@Vikaspal I do not understand why are you spending your energy on doing something that is not even required in the problem? And please use ide.codingblock.com to share your codes.

@Ishitagambhir sure but i bit confused, how to i am trying to iteratively first.

@Vikaspal if you want to it iteratively, for i = 0, i < str.length() -1, you should check if str[i] == str[i + 1], if yes then insert a * at i + 1 index, and continue as before.

@Ishitagambhir so sorry the problem it pretty simple , but i made it so complicated


when i am solving recurrsion problem go deeper then i stuck but when i think ya it will be happen automatically then i able to think about the constraints and approach . So any tips for me while handling recursion problem. In this problem i go iteratively then build the recursive solution?

@Vikaspal in recursion problems, try to divide the problem into smaller subproblems, and solve the rest of the problem using the assumption that the recursive calls will take care of the subproblems as well.

@Vikaspal okay but when i trying to create the recurrence tree and function call in the stack main memory so the problem arise…

@Vikaspal what problem arises?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.