All submissions

Remove Duplicate Characters from a String

Code

#include <stdio.h>
#include <stdint.h>
#include<string.h>
void remove_duplicates(char *str) {
	//Your logic here
    char s[100];
    int index=0;
    while(*str!='\0'){
        int flag=0;
        for(int i=0;i<index;i++){
            if(s[i]==*str){
                flag=1;
                break;
            }
        }
        if(flag==0){
            s[index]=*str;
            index++;
        }
        str++;
    }
    s[index]='\0';
    printf("%s",s);
}

int main() {
    char str[101];
    fgets(str, sizeof(str), stdin);

    // Remove newline
    uint8_t i = 0;
    while (str[i]) {
        if (str[i] == '\n') {
            str[i] = '\0';
            break;
        }
        i++;
    }

    remove_duplicates(str);
    return 0;
}

Solving Approach

 

 

simple pointer approach and string helped me to solve the problem

Loading...

Input

programming

Expected Output

progamin