I would say they can be used interchangeably, but sometimes "the" and "a" sound better in different situations. You know how people emphasize the importance of something by saying "It's not just a________, it's THE ____________"? For example: "In the 1940s, Humphrey Bogart wasn't just an actor, he was the actor." Well, the same kind of thinking applies here.
"Instead, armed with a computer science degree and <a knack for>
numbers, Mr. Kim became a star technology analyst on Wall Street." - You could say "the knack for", but "a knack" sounds better because there are various types of "knacks" people can have for numbers. The one Mr. Kim had in particular, helped him with technology analysis.
"Cook caught Randall's eye when the MCC came to play against the Bedford first XI. The guests were a man short, so the 14-year-old Cook stood in for them. He was supposed to be making up the numbers, but he ended up making a century. Cook was blessed with <the knack for> seizing an opportunity. He was just 18 when he made his first-class debut for Essex and he made an unbeaten 69 in the second innings, batting in partnership with Andy Flower, who is now England's head coach." - Notice how the author of this passage spends time describing Cook, and building up a sort of legendary status for him. Cook sounds like someone who, in another lifetime, would not have ended up where he is now if it weren't for one little opportunity. This is highlighted in the sentence, "He was supposed to be making up the numbers, but he ended up making a century." Seizing opportunities, to this author, seems to be a characteristic of great men, so when he says "the knack," he is trying to set Cook apart from other men who have had opportunities and didn't properly take advantage of hem.
"Philip Roth is neither Shakespeare nor Wilde, but he has always possessed <the knack of> confounding his audience." - As strange as it sounds, "the knack of" is technically correct. When you say someone has a "knack for" or "of" something, it describes varying degrees of skill. It could mean you have the hang of something, or you have a gift for it. It all depends on the context. "Confusing the audience" sounds like something Shakespeare and Wilde had in common (which makes sense when you read them), and the author is saying Roth has that same "knack" (and he uses "the"--because it is a particular type of knack), even though his writing is not of the same caliber.