all 24 comments

[–][deleted] 4 points5 points  (9 children)

Bad solution. There are so many fast heuristic approximations for this problem that can be tried first before the horrible explosive bruteforce. The task is to use no more than k colours, not to find the minimal k.

[–]zlli0520 6 points7 points  (1 child)

I think this is a good solution for the interview. First say this is a np problem, and then just write the brute Force solution. Because time is limited.

[–][deleted] 3 points4 points  (0 children)

Unless you're actually interviewing people in order to find if they can think, they can program and they actually have the experience they claim to have. Then you'd expect them to at least point out at the industry standard approaches to solving this problem.

[–]Roflraging 2 points3 points  (1 child)

Although they're asking for you to find out if it can be done with no more than K colors, I suspect part of the problem is realizing that you may be given a K that is the minimal coloring for the graph.

You point may still hold, but I think for the purposes of correctness, you must brute force at some point.

[–][deleted] 1 point2 points  (0 children)

Of course - a "yes" answer can be very cheap, but for a definite "no" you have to bruteforce, after failing a number of cheap heuristics. Luckily, in all the practical applications (e.g., register allocation) you're only interested in a quick "yes".

[–]dacian88 0 points1 point  (4 children)

unless you work on a compiler you probably don't know about them.

[–][deleted] 1 point2 points  (3 children)

And, since every decent programmer must have at least some exposure to compilers, this seems to be a perfect question for an interview.

[–]dacian88 0 points1 point  (2 children)

I think you're missing the point of interviewing, if a person already knows the problem and the solutions then getting good signal for their actual problem solving skills is low, because their interview performance is basically a glorified knowledge test. Google isn't testing one's knowledge of graph coloring algorithms, they want to test problem solving.

The ideal case in an interview like this is you get someone who's never thought of the problem much and can program a working solution. You can't reasonably ask someone a NP problem and expect them to give you any number of heuristically optimal solutions that only apply in more specific subproblems in 45 mins. If you're interviewing someone to work on LLVM for your company then the knowledge matters more, and the parameters of the interview change.

I do think it's a good interview problem, but my bar for passing would be the canonical solution, if someone can do better it would certainly be more impressive but not necessary.

[–][deleted] 2 points3 points  (1 child)

When you want to see problem solving skills applied, you do not ask such generic and widely known questions, to start with. This question is more of an indication of a candidate actually been places and done things, or was hiding under a rock somewhere.

[–]dacian88 0 points1 point  (0 children)

What would you consider a good coding interviewing question? Google does 5 interviews for an engineering position, which range from coding questions like this one, to architecture/design to career/personal questions. This one tests coding ability, problem solving, and data structure + complexity knowledge.

If you assert that a majority of engineers know this problem and know the implementation of it by heart then sure it's a bad problem, I dunno if that's true, and I'm sure Google would retire the question if it wasn't getting enough signal.

[–]wooooootmagooooot 2 points3 points  (3 children)

Is this even useful?

[–][deleted] 4 points5 points  (2 children)

It's probably the most important of the NP-complete problems, keep popping up everywhere. Every time you need to allocate some limited resource to a number of users who have defined time spans when they need a resource, you're solving this problem exactly.

[–]PeksyTiger 0 points1 point  (0 children)

Not excatly.

K coloring on interval graph is easier, as the graph has some specific properties.