Printing numbers without duplicates

Given input as a string which contains duplicate numbers where duplicates are in an order. You has to print the output in an order without duplicates.

INPUT
"111122223333"

OUTPUT
123

C Solution

#include<stdio.h>
#include <string.h>

int main()
{
    char str[14];
    scanf("%s",str);
    for(int i=0;i<strlen(str);i++)
    {
        printf("%c",str[i]);
        if(str[i-1]!=str[i]&&str[i]!=str[i+1])
          printf("%c",str[i]);
    }
  return 0;


If anyone come up with better solution leave it in comments.
Keep Programming..!! 

Comments

Popular posts from this blog

Balanced Binary Tree

First Unique Character in a String

Majority Element

Smallest Range II