InternDoor

TCS interview prep

18 practice questions on the topics candidates reported from TCS interviews, with answers. The questions are ours; each one links to the interview report that names its topic.

Practise them as a timed round9 roles open at Tata Consultancy Services

DSA 2

  1. DSAEasy

    In an unweighted graph, which algorithm finds the path with the fewest edges from a start vertex to every other vertex?

    1. Depth-first search
    2. Kruskal's algorithm
    3. Topological sort
    4. Breadth-first search
    Show the answer

    D. Breadth-first search

    BFS visits vertices in order of their distance in edges, so the first time it reaches a vertex is along a shortest path. DFS can reach a vertex by a long path first.

    This topic is named in a candidate’s interview report: NQT Digital interview, on GeeksforGeeks.

  2. DSAMedium

    How does Kruskal's algorithm build a minimum spanning tree?

    1. It grows one tree from a start vertex, always adding the cheapest edge leaving the tree
    2. It takes the edges from lightest to heaviest and adds each one that does not form a cycle
    3. It removes the heaviest edge of every cycle, starting from the full graph
    4. It runs Dijkstra's algorithm from every vertex
    Show the answer

    B. It takes the edges from lightest to heaviest and adds each one that does not form a cycle

    Sort the edges by weight and keep an edge only if its two ends are not yet connected, which union-find checks quickly. Growing a single tree from a start vertex is Prim's algorithm.

    This topic is named in a candidate’s interview report: NQT Digital interview, on GeeksforGeeks.

Java 2

  1. JavaEasy

    Which one do you need to compile Java source code, not only to run it?

    1. The JDK
    2. The JRE on its own
    3. The JVM on its own
    4. A Java-enabled browser
    Show the answer

    A. The JDK

    The JDK (Java Development Kit) has the compiler, javac, and everything needed to run programs. The JRE is the JVM plus the standard library, enough to run compiled bytecode. The JVM is the part that executes the bytecode.

    This topic is named in a candidate’s interview report: NQT Digital interview, on GeeksforGeeks.

  2. JavaEasy

    Can a constructor be declared static in Java?

    1. Yes, to share it between objects
    2. No: a constructor initialises a particular new object, so it cannot belong to the class alone; use a static block or a static factory method for class-level work
    3. Yes, but only in abstract classes
    4. Only in interfaces
    Show the answer

    B. No: a constructor initialises a particular new object, so it cannot belong to the class alone; use a static block or a static factory method for class-level work

    static means "no object needed", while a constructor exists to set up this object, so the compiler rejects static there. A static initialiser block runs once when the class loads.

    This topic is named in a candidate’s interview report: Digital interview, 2025, on Reddit.

Python 4

  1. PythonEasy

    What does this print?

    a, b = 0, 1
    for _ in range(6):
        a, b = b, a + b
    print(a)
    1. 5
    2. 13
    3. 6
    4. 8
    Show the answer

    D. 8

    Each pass moves the pair one step along the Fibonacci series 0, 1, 1, 2, 3, 5, 8, so after 6 passes a is 8. The right-hand side is worked out from the old a and b before either changes, so no temporary variable is needed.

    This topic is named in a candidate’s interview report: NQT Ninja interview, on GeeksforGeeks.

  2. PythonEasy

    What does this print?

    a, b = 5, 9
    a = a + b
    b = a - b
    a = a - b
    print(a, b)
    1. 5 9
    2. 14 5
    3. 9 5
    4. 9 14
    Show the answer

    C. 9 5

    After a = a + b, a is 14. b = 14 - 9 = 5, the old a. a = 14 - 5 = 9, the old b. The values are swapped without a third variable (in fixed-size integer languages the sum can overflow, which is why XOR swaps are also taught).

    This topic is named in a candidate’s interview report: Digital interview, 2025, on Reddit.

  3. PythonEasy

    What does this print?

    n = 3
    for i in range(1, n + 1):
        print(" " * (n - i) + "*" * (2 * i - 1))
    1. A right-angled triangle of 1, 2 and 3 stars
    2. Three rows of 3 stars
    3. A centred pyramid of 1, 3 and 5 stars
    4. An upside-down pyramid of 5, 3 and 1 stars
    Show the answer

    C. A centred pyramid of 1, 3 and 5 stars

    Row i has n - i leading spaces and 2i - 1 stars: " *", " ***" and "*****". The spaces shrink as the stars grow, which centres each row.

    This topic is named in a candidate’s interview report: Digital interview, 2025, on Reddit.

  4. PythonEasy

    What does this print?

    import re
    
    s = "ab12c3d45"
    print("".join(ch for ch in s if ch.isdigit()), re.findall(r"\d+", s))
    1. 12345 ['12', '3', '45']
    2. 12345 ['1', '2', '3', '4', '5']
    3. ['12', '3', '45'] 12345
    4. ab12c3d45 12345
    Show the answer

    A. 12345 ['12', '3', '45']

    The first approach keeps every digit character. The regular expression \d+ instead finds runs of digits, so neighbouring digits stay together as numbers.

    This topic is named in a candidate’s interview report: Digital interview, 2025, on Reddit.

OOP 1

  1. OOPEasy

    Which of these is NOT one of the four pillars of object-oriented programming?

    1. Encapsulation
    2. Compilation
    3. Inheritance
    4. Polymorphism
    Show the answer

    B. Compilation

    The four pillars are encapsulation, abstraction, inheritance and polymorphism. Compilation is how source code becomes something a machine can run, in any style of programming.

    This topic is named in a candidate’s interview report: NQT Digital interview, on GeeksforGeeks.

DBMS and SQL 3

  1. DBMS and SQLMedium

    How does TRUNCATE TABLE differ from DELETE FROM a table with no WHERE?

    1. They are identical in every database
    2. TRUNCATE drops the table definition too
    3. DELETE cannot remove every row
    4. TRUNCATE removes every row at once without logging each one or firing row triggers, and usually cannot take a WHERE
    Show the answer

    D. TRUNCATE removes every row at once without logging each one or firing row triggers, and usually cannot take a WHERE

    DELETE removes rows one by one, can filter with WHERE and fires row triggers. TRUNCATE deallocates the data in bulk, which is much faster on big tables, and the table itself remains. Whether it can be rolled back depends on the database.

    This topic is named in a candidate’s interview report: Digital interview, 2025, on Reddit.

  2. DBMS and SQLMedium

    When is a document database such as MongoDB usually a better fit than a relational database?

    1. When many tables must be joined with strict transactions across them
    2. When the data is a few small tables with a fixed structure
    3. Whenever the data must survive a restart
    4. When each record is read and written as a whole and its fields vary from record to record
    Show the answer

    D. When each record is read and written as a whole and its fields vary from record to record

    A document keeps a record and its nested details together without one fixed schema, which suits catalogues, profiles and event logs. Relational databases are stronger when data is shared between tables and changes must span them in one transaction.

    This topic is named in a candidate’s interview report: NQT Digital interview, on GeeksforGeeks.

  3. DBMS and SQLMedium

    Table a has ids 1, 2 and 3. Table b has ids 2, 3 and 4. How many rows does this query return?

    SELECT a.id, b.id
    FROM a FULL OUTER JOIN b ON a.id = b.id;
    1. 2
    2. 4
    3. 3
    4. 6
    Show the answer

    B. 4

    Ids 2 and 3 match, giving two rows. Id 1 appears with NULL for b, and id 4 with NULL for a. An INNER JOIN would return 2 rows and a LEFT JOIN 3.

    This topic is named in a candidate’s interview report: NQT Ninja interview, on GeeksforGeeks.

Operating systems 1

  1. Operating systemsEasy

    On Linux, which directory holds the system-wide configuration files?

    1. /bin
    2. /tmp
    3. /home
    4. /etc
    Show the answer

    D. /etc

    /etc holds settings such as /etc/hosts and /etc/passwd. /bin holds essential commands, /tmp temporary files and /home each user's own files.

    This topic is named in a candidate’s interview report: NQT Digital interview, on GeeksforGeeks.

Web development 4

  1. Web developmentEasy

    Which attribute makes a link open its page in a new tab?

    1. target="_blank" on the <a> element
    2. rel="new" on the <a> element
    3. tab="new" on the <a> element
    4. href starting with "new:"
    Show the answer

    A. target="_blank" on the <a> element

    target="_blank" opens a new browsing context, usually a tab. rel="noopener" stops the new page reaching back to yours through window.opener; current browsers apply it to _blank by default, but adding it costs nothing.

    This topic is named in a candidate’s interview report: NQT Ninja interview, on GeeksforGeeks.

  2. Web developmentEasy

    Which is true of a GET request compared with a POST request?

    1. GET is encrypted and POST is not
    2. A POST can be bookmarked and a GET cannot
    3. GET can only fetch images
    4. GET sends its data in the URL and should not change anything on the server; POST sends data in the body to create or change something
    Show the answer

    D. GET sends its data in the URL and should not change anything on the server; POST sends data in the body to create or change something

    GET is for reading: its query string ends up in browser history and server logs, so it must never carry a password. Neither method encrypts anything by itself; HTTPS encrypts both.

    This topic is named in a candidate’s interview report: NQT Digital interview, on GeeksforGeeks.

  3. Web developmentMedium

    JavaScript in a web page runs on a single thread. How does it wait for a network response without freezing the page?

    1. fetch starts the request and returns at once; when the response arrives, its callback is queued and the event loop runs it
    2. It starts a new JavaScript thread for every function call
    3. It blocks, but too briefly for anyone to notice
    4. The server writes the result straight into a variable
    Show the answer

    A. fetch starts the request and returns at once; when the response arrives, its callback is queued and the event loop runs it

    The request runs inside the browser, outside the JavaScript thread. When it completes, the promise callback goes on a queue, and the event loop runs it once the current code has finished. A long loop in your own code still freezes the page.

    This topic is named in a candidate’s interview report: NQT Digital interview, on GeeksforGeeks.

  4. Web developmentEasy

    Which call returns the first element on the page that matches a CSS selector?

    1. document.querySelector(".card")
    2. document.getElement(".card")
    3. document.select(".card")
    4. window.find(".card")
    Show the answer

    A. document.querySelector(".card")

    querySelector takes any CSS selector and returns the first match, or null. querySelectorAll returns every match. getElementById is the older way to find one element by its id.

    This topic is named in a candidate’s interview report: NQT Digital interview, on GeeksforGeeks.

Software engineering 1

  1. Software engineeringEasy

    In a web application, what is an API?

    1. A defined set of requests one program can make to another, such as GET /users/42 returning that user as JSON
    2. The database where the server keeps its data
    3. The HTML page the browser shows
    4. A kind of server hardware
    Show the answer

    A. A defined set of requests one program can make to another, such as GET /users/42 returning that user as JSON

    The client, a browser or an app, sends requests to the server through the API and gets data back, usually as JSON. The API is the contract: which endpoints exist, what they take and what they return.

    This topic is named in a candidate’s interview report: NQT Digital interview, on GeeksforGeeks.

Prep for other employers

All employers
See who is hiring after TCS

Engineering internships and entry-level jobs in India, newest first.