Where did i go wrong ?

(extremely sorry , made a mistake in providing the information, edited )
I did something similar to wat most of the guys did, but i got a ‘wrong answer’ .
It did the following :
i made 5 groups of number ( in string A)
a----- no>7
b-----no==7
c-----no<7 && no>4
d-----no==4
e-----no<4
(similar goes for B string too) ( v,w,x,y,z)
for every number greater than 7 (v)(in B string), i paired it up with nos in grp … a,c,e,d,b( in decreasing order of priority).
for every number == 7 (w)(in B string), i paired it up with nos in grp … c,e,d,b( in decreasing order of priority).
for 7<number<4(x) … e,d,c
n==4(y) … e ,d
(remaining numbers<4 don’t matter)
this was for numbers in B string … if any number is left in A string to be paired, similar order is used.

the crux is … to avoid 7’s and 4’s to be paired with any number higher then them … hence pair the higher number with useless numbers.

But i am getting wrong answer , could someone please point out the mistake in this algo.

Are you first pairing n>7s in B with n>7s in A? From your explanation it doesn’t look like you are. Try your algorithm with A=87643, B=87432. In your case, you’re pairing 8 in B with 6 in A; then 7 in B with 3 of A. So, you’re left with the answer 774, while you can get 7744.

1 Like

You explanation in not very clear. So I can’t point out where you have logical mistake.

Try this test
84847487764
19887294978
You solution gets
7777744
while the correct answer is
77777
Here in B we have only 5 digits <=7 : 17247.
So the answer can’t have more than 5 digits like in your output.

Another failing test is
773477789
144709876
You solution gets
7777777
while the correct answer is
77777774
Similarly here in A we have only 7 digits <=7 : 7734777.
So the answer can’t have more than 7 digits like in your output.

1 Like

@deebee hey m sorry … i provided the wrong info.
i am pairing the no > 7 in A with no>7 in B first , only after nos in B are exhausted i move on to next groups of number.

@anton_lunyov hey m sorry man, provided wrong info.
edited the problem … also i made a small mistake in the code … repaired it … and now got AC …thanks

hey got AC … thanks … had some other glitch in the code…