To paraphrase Cracking the Coding Interview: Most companies are aware that their tests will result in some false negatives. Particularly at the bigger-name companies that get hundreds and hundreds of applicants-- they're fine with that. What they want to avoid more than anything is false positives. A false positive means that they're wasting their money on someone who isn't going to help, who can potentially introduce more bugs to the codebase than a qualified candidate, and who ultimately costs the company more than they bring to the table.
In short: You're absolutely right. This isn't a real-world scenario, and it's testing you beyond what should be expected, especially of a junior candidate. But that's not really their concern-- their concern is to make sure that they get the best candidate least likely to make any errors.
edit: Here's a proposed scenario. We have three companies with identical holdings and reputations in the market. Allare seen as very attractive job prospects.The exact same pool of 10,000 candidates applies to each company.
Of the 10,000 candidates, 100 of them are qualified and excellent candidates. 9,900 of them are not suitable for the position, and could potentially damage the company's infrastructure.
Company A decides that it is critical that they look at all of the candidates and pick out only the ones that they want. In round 1 of interviews, they use a basic FizzBuzz test, and they knock out 5,000 right away. In round two, they send out an interview question that's at about the level of difficulty that they expect for the job, and they narrow it down to around 300 candidates. They conduct in-person interviews for those last 300 candidates, and they narrow it down to the 100 qualified candidates. They compare those candidates to one another, and they select their favorite.
Company B decides that they really only care about two things-- hiring quickly and getting a qualified candidate. They send out an impersonal FizzBuzz complete-by-email test to complete over email, and they weed out the same 5000 people who didn't know what they were doing. The second round of interviews requires bitwise operators, bit shifting, and all manner of niche, interview-only questions that 99.999% of the people in this role would never have to deal with.This narrows their search down to 23 candidates. Company B is confident that any of the 23 candidates will do the job well. They can interview them individually to find a good personality fit, then move on to the actual work.
Company C just sends out a basic FizzBuzz quiz, and they have 5000 candidates that they decide are all good fits (many false positives). They select one at random, because time is money, darn it-- I'm sure they can all do the job! They realize after the full on-boarding process, getting benefits set up, etc. that their candidate just googled the answer to the FizzBuzz quiz and does not know anything about the relevant duties of the job.
Companies A and B can eventually arrive at the same final point of selecting a single qualified candidate-- but company B has done it in significantly less time, and at significantly less cost of manpower to search through candidates. Yes, they booted out a few people unfairly-- but especially for something low or mid-level, they don't need a brilliant developer. They just need a developer-- someone who can perform roughly as good as the next guy.
When the end of the year comes around and companies A, B, and C have to compare against one another, if all else is equal, Company B will have retained more money and had more time and energy to devote to projects than Company A. Company C, who selected a false positive, now has to go back to the hiring process, having lost both money AND time. It makes good business sense to weed candidates out with minimal concern for false negatives so long as you can still retain a reasonable number of true positives.