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

Mayukh_1 commented: This is a very good question +1

Recommended Answers

All 6 Replies

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.