it should be if(a[current]==a[previous])
if it is not equal than there is no duplicacy, if current is copied in previous without duplicacy then it will change the code
Eg: Input string - Codding
please explain
it should be if(a[current]==a[previous])
if it is not equal than there is no duplicacy, if current is copied in previous without duplicacy then it will change the code
Eg: Input string - Codding
please explain
the code is correct, it should be a[current]!=a[prev];
for eg. say input is ccooooddinng, your output should be “coding”.
prev always points to the last index of so far formed solution.
the condition will be first time true when current = 2 and prev = 0, it means we got next character(which is ‘o’) after skipping all duplicates of c. so partial solution till now should be ‘co’, and thats why prev++, and a[prev] = a[current];
this means array will be coooooddinng at this time and prev =1 , the partial solution is ‘co’ from index 0 to prev.
thanks
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.