ProgrammingModerateAmazon OA · Flipkart coding round

What is the usual fastest way to read n = 10^6 integers from one input line in Python for a judge?

  1. A. Read the whole input with sys.stdin.buffer.read().split() and convert the needed tokens with map(int, ...)
  2. B. Call input() once per number inside a loop of 10^6 steps
  3. C. Use eval(input()) on the whole line and unpack the result
  4. D. Read the file character by character with sys.stdin.read(1)

Correct answer: A. Read the whole input with sys.stdin.buffer.read().split() and convert the needed tokens with map(int, ...)

Reading all bytes in one call and splitting avoids a Python-level call per number. eval is slow and unsafe, and character reads add overhead per character.

More Python Programming questions

Exams that ask this topic