I was asked to write a program to eliminate the reoccurrence of numbers in an interview? For example if I give the input as 2233555697 then the output should be 235697

Edited by aravindm

Votes + Comments
This is a very good question
2 Years
Discussion Span
Last Post by Mayukh_1

Use this logic..
Sorry this code is in python not in c...but you can understand the logic

number = 123134254
reverse = 0
while number > 0:
    reverse = (reverse * 10) + (number % 10)
    number /= 10
b = 0
answer = 0
while reverse > 0:
    a = 1 << (reverse % 10)
    if (a & b) == 0:
        answer = (answer * 10) + (reverse % 10)
        b |= a
    reverse /= 10
print answer

Edited by Mayukh_1


If the input is 223322, what should the output be? 23 or 232?
The output should be 23


The real essence of the program is to do it without any array or stack or queue data structures.


"without arrays/stacks/queues" makes this a lot more interesting - presumably that bans dictionaries as well?

You could use a nested loop like (pseudocode)

for i = 0 to string length
  for  j = i+1 to string length
     if char j == char i, remove char j

It will ban any kindda data structure like this..The only things that can be used is logical, arithmatic, bitwise operators, and normal basic variables like integer, char, long etc..I don't if his question is the same as what I am telling, but this version I have solved in some online contest

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.