Keshav DhandhaniaFormer TopCoder India #1 · 3y

**Hint 1: **

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?

**Hint 2: **

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?

**Hint 3: **

The problem reduces the maximizing the number of 7's in C. And then the number of 4's.

How do we achieve that?

**Hint 4:**

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)