#include <stdio.h>
#include <stdint.h>
void remove_duplicates(char *str) {
//Your logic here
// use 2 pointers
bool hash[256] = {0};
uint8_t write_idx = 0, read_idx = 0;
while (str[read_idx] != '\0') {
uint8_t ch = (uint8_t)str[read_idx];
if (!hash[ch]) {
str[write_idx] = str[read_idx];
hash[ch] = 1;
write_idx++;
}
read_idx++;
}
str[write_idx] = '\0';
}
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);
printf("%s", str);
return 0;
}
Input
programming
Expected Output
progamin