Keshav DhandhaniaFormer TopCoder India #1 · 2y
We want the lexicographically largest possible string C as possible. C consists of 4's and 7's. We can rearrange digits of numbers A and B as we want. What does all of this imply in terms of digits of C?
It implies that we can always ensure all the 7's in C appear first, and then all the 4's.
Given this, what does the problem reduce to?
The problem reduces the maximizing the number of 7's in C. And then the number of 4's.
How do we achieve that?
Be greedy in arranging the digits of A and B such that we get as many 7's as possible. Then be greedy in arranging the digits of A and B such that we get as many 4's as possible.
Read more… (241 words)