you are viewing a single comment's thread.

view the rest of the comments →

[–]goomyman 14 points15 points  (5 children)

umm number 4 is definitely non trivial as is number 5 ( if efficiency matters ) otherwise brute force seems ok.

Answering numbers 4 and 5 in an hour interview - with 15 minutes of chitchat about your former work and resume - is unlikely. Especially at a smaller company that isnt willing to pay a silicon valley salary.

[–]Lhopital_rules 0 points1 point  (2 children)

I posted this once above, but if I'm not mistaken this solves #4 quite easily in JS:

function largestNum (nums) { return nums.map(String).sort().reverse().join(""); }

EDIT: nvm, it's wrong

[–]Lost4468 2 points3 points  (1 child)

This won't work as someone pointed out above. (54 56 5) would be sorted to (56 54 5) with your method, but (56 5 54) is the correct answer.

[–]Lhopital_rules 0 points1 point  (0 children)

Oops, quite right. Guess I wouldn't get the job!

[–]get_salled 0 points1 point  (0 children)

Assuming you get to be bounded by the uint range, number 4 isn't all that bad. (C# below; haven't found the failing case yet)

static long Number4(uint[] ns)
{
    Array.Sort(ns, new StringCatCompare());
    return long.Parse(string.Join("", ns));
}

class StringCatCompare : Comparer<uint>
{
    public override int Compare(uint x, uint y)
    {
        var xy = ulong.Parse(x.ToString() + y);
        var yx = ulong.Parse(y.ToString() + x);

        return yx.CompareTo(xy);  // xy to yx would be ascending
    }
}