The TCS Digital interview is a different animal from the Ninja interview. Where Ninja Technical rounds ask you to explain concepts, Digital rounds ask you to implement them, analyse their complexity, and then defend why you chose one approach over another. Where Ninja HR rounds focus on attitude and communication, Digital HR rounds include live coding questions and expect you to articulate your technical thinking as clearly as your career motivations. This guide prepares you for all of it: the technical depth across every CS domain, the whiteboard coding approach, the system design basics that freshers need to know, and the HR hybrid that requires both human and algorithmic answers.

TCS Guide

Understanding the TCS Digital Interview Structure

What Makes It Different from Ninja

The TCS Ninja Technical Interview lasts 30-40 minutes and tests conceptual understanding. You are asked to explain data structures, define OOP principles, and write simple code segments. Correct definitions and a working project discussion usually carry you through.

The TCS Digital Technical Interview lasts 60-90 minutes and tests applied knowledge at depth. The interviewer may spend 20 minutes on a single data structure, asking you to implement it from scratch, analyse its time complexity for each operation, suggest optimisations, and then ask a follow-up problem that uses it. Where Ninja expects you to know what a BST is, Digital expects you to implement insert, delete, and search, explain the worst-case degradation, and discuss AVL trees as a remedy.

The three hallmarks of the Digital interview:

Depth over breadth. Every topic the interviewer picks is explored fully before moving on. A Digital candidate should expect 3-5 deep topics rather than 10-15 surface topics.

Whiteboard or verbal coding. You will be asked to write code, either on paper, a whiteboard, or in a shared editor. The code must be syntactically close to correct and logically correct. Comments explaining what each section does are expected and valued.

“Why” questions. After every implementation or explanation, the Digital interviewer asks “why.” Why did you choose this data structure? Why is this O(N log N) rather than O(N)? Why is this approach better than the brute force? The ability to articulate your reasoning is as important as the reasoning itself.

Interview Format

Round 1: Technical Interview (60-90 minutes) One or two senior technical panelists. Coverage: DS/Algorithms, DBMS, OS, Networks, OOP, and your project. Expect at least one live coding problem written on paper or described verbally.

Round 2: HR and Management Round (30-45 minutes) Usually a Management Representative (MR) or HR lead. Behavioural questions, career goals, Digital profile positioning. Often includes a light technical question or asks you to explain a technical concept in simple terms. Coding questions at this stage are possible but not universal.

Multiple rounds: For some Digital hiring cycles, candidates face 2-3 technical rounds before the HR round. Prepare for the possibility of back-to-back technical evaluation by keeping your energy and precision consistent across rounds.


Section 1: Data Structures - Implementation Level Questions

Implement Stack Using Queue(s)

This is one of the most commonly asked implementation questions at Digital level. It tests whether you can use one data structure to simulate another - a classic problem that reveals algorithmic thinking.

Approach 1: Push-heavy (simple pop) Maintain two queues Q1 and Q2.

  • Push: enqueue to Q1.
  • Pop: dequeue all elements from Q1 to Q2 except the last one. The last element is the stack top. Swap Q1 and Q2.

Approach 2: Pop-heavy (simple push) Maintain one queue Q1.

  • Push: enqueue to Q1, then rotate all previous elements to the back (dequeue and re-enqueue N-1 times where N is the new size). The last pushed element is always at the front.
  • Pop: simply dequeue.

Complexity analysis: Approach 1: Push O(1), Pop O(N). Approach 2: Push O(N), Pop O(1).

What the interviewer is looking for: That you can enumerate both approaches, explain the complexity trade-off of each, and choose the right one based on the given constraint (“If pops are more frequent than pushes, which do you prefer?”).

Code (Approach 2 - Python-style pseudocode for verbal explanation):

push(x):
    size = Q1.size()
    Q1.enqueue(x)
    for i in range(size):
        Q1.enqueue(Q1.dequeue())

pop():
    return Q1.dequeue()

LRU Cache Implementation

LRU (Least Recently Used) cache evicts the least recently accessed entry when the cache is full. This question is a favourite at Digital level because it requires combining a HashMap with a Doubly Linked List.

Data structure: HashMap (for O(1) access by key) + Doubly Linked List (for O(1) move-to-front and remove-from-back).

Operations:

  • get(key): If key exists in cache, move the corresponding node to the front (most recently used), return value. If not, return -1.
  • put(key, value): If key exists, update and move to front. If not, insert at front. If cache is at capacity, remove the node at the back (LRU) and remove from HashMap.

Why this data structure combination: HashMap alone supports O(1) lookup but not O(1) ordered removal. Array supports ordered access but not O(1) lookup. Doubly linked list supports O(1) insertion and removal at any point (given a node reference). The combination achieves O(1) for all operations.

Expected interview discussion:

  • “Why doubly linked list and not singly linked?” → To remove a node, you need to update the previous node’s next pointer. Singly linked gives only the current node; you cannot update the previous without traversal.
  • “What’s the time complexity of your get and put?” → O(1) for both.
  • “What’s the space complexity?” → O(capacity) for the cache entries.

Binary Search Tree Operations

Insert (recursive):

insert(node, key):
    if node is null: return new Node(key)
    if key < node.key: node.left = insert(node.left, key)
    elif key > node.key: node.right = insert(node.right, key)
    return node

Time: O(H) where H = height. O(log N) balanced, O(N) worst case (sorted insertion).

Delete (the hardest BST operation): Three cases:

  1. Node has no children: simply remove.
  2. Node has one child: replace node with its child.
  3. Node has two children: find in-order successor (smallest node in right subtree), copy its value to the current node, delete the in-order successor.

BST worst case discussion: Inserting sorted data into a BST produces a degenerate tree (all nodes in a chain). This degrades all operations from O(log N) to O(N). Solutions: AVL trees or Red-Black trees that self-balance.

In-order traversal gives sorted output. This is the key property of BSTs and a common follow-up question.

Graph Representations

Two primary representations with specific use cases:

Adjacency Matrix: 2D array where matrix[i][j] = 1 if edge exists between nodes i and j.

  • Space: O(V²) where V = number of vertices.
  • Edge existence check: O(1).
  • Finding all neighbours of a node: O(V) (must scan entire row).
  • Best for: Dense graphs where most possible edges exist.

Adjacency List: Array of lists where list[i] contains all neighbours of node i.

  • Space: O(V + E) where E = number of edges.
  • Edge existence check: O(degree) = O(V) worst case.
  • Finding all neighbours: O(degree) = O(V) worst case.
  • Best for: Sparse graphs where most possible edges do not exist.

The standard interview question: “When would you choose adjacency matrix over adjacency list?” Answer: When the graph is dense (E ≈ V²), the space costs are similar but the O(1) edge check of the matrix is advantageous. When the graph is sparse (E « V²), adjacency list is more space-efficient.


Section 2: Algorithms - Complexity and Problem Solving

Complexity Analysis Framework

Every algorithm question at Digital level ends with: “What is the time complexity? What is the space complexity? Can you improve it?”

The analysis approach:

  1. Identify the dominant loop structure (nested loops = usually O(N²), single loop = O(N), loop with halving = O(log N)).
  2. Identify space usage (extra arrays or data structures proportional to input size).
  3. Ask: is there an information-theoretic lower bound? (Comparison-based sorting cannot be better than O(N log N)).

Common complexity patterns:

Pattern Time Complexity
Single loop over N elements O(N)
Nested loops (both over N) O(N²)
Binary search or halving O(log N)
Loop with halving (e.g., heap operations) O(N log N)
Recursive divide-and-conquer (halving) O(N log N)
Recursion with all subsets O(2^N)
Recursion with all permutations O(N!)

Whiteboard Coding Approach

When asked to write code on paper or describe verbally:

Step 1: Restate the problem. “So you want me to find the k-th largest element in an unsorted array. Is k guaranteed to be valid? Can there be duplicates?” This buys thinking time and demonstrates precision.

Step 2: Think out loud about approach. “The brute-force would be to sort the array in O(N log N) and return the k-th from the end. But we can do better with a min-heap of size k in O(N log k)…” This demonstrates algorithmic thinking before a single line is written.

Step 3: Write clean pseudocode first, then actual code. Pseudocode is faster to write and communicates the algorithm clearly. If the interviewer says “that looks right, go ahead and code it,” then write the actual code.

Step 4: Trace through a small example. Before calling the code done, trace it with a 3-4 element example. This catches off-by-one errors and index bugs in real-time.

Common Coding Problems at Digital Level

Problem: K-th Largest Element

  • Brute force: sort, return arr[N-k]. O(N log N) time, O(1) extra space.
  • Optimal: min-heap of size k. For each element, if larger than heap top, replace. O(N log k) time, O(k) space.
  • Alternative: QuickSelect (average O(N), worst O(N²)). Can guarantee O(N) with median-of-medians pivot selection but complex to implement.

Problem: Two Sum

  • Brute force: check all pairs. O(N²).
  • Optimal: HashMap. For each element, check if complement (target - element) is in map. O(N) time, O(N) space.

Problem: Detect Cycle in Linked List

  • Floyd’s cycle detection (tortoise and hare): slow pointer advances 1 step, fast pointer advances 2. If they meet, cycle exists. O(N) time, O(1) space.

Problem: Maximum Depth of Binary Tree

maxDepth(root):
    if root is null: return 0
    return 1 + max(maxDepth(root.left), maxDepth(root.right))

O(N) time (visit every node), O(H) space for recursion stack.


Section 3: DBMS - Advanced SQL and Concepts

Complex SQL Queries

Problem: Find the second-highest salary in a table with possible duplicates.

-- Using subquery
SELECT MAX(salary) AS second_highest
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

-- Using DENSE_RANK (handles duplicates correctly)
SELECT salary AS second_highest
FROM (
    SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk
    FROM employees
) ranked
WHERE rnk = 2;

The Digital interviewer will ask you to distinguish RANK, DENSE_RANK, and ROW_NUMBER:

  • ROW_NUMBER: Unique number for each row, no ties.
  • RANK: Ties get the same rank, but next rank skips (1, 1, 3, 4).
  • DENSE_RANK: Ties get the same rank, next rank does not skip (1, 1, 2, 3).

Problem: Employees who earn more than the average salary of their own department.

SELECT e.name, e.salary, e.department_id
FROM employees e
JOIN (
    SELECT department_id, AVG(salary) AS avg_salary
    FROM employees
    GROUP BY department_id
) dept_avg ON e.department_id = dept_avg.department_id
WHERE e.salary > dept_avg.avg_salary;

Problem: Find departments with more than 5 employees who joined in the last 2 years. (Note: no time-specific references - use a parameter or generic interval)

SELECT department_id, COUNT(*) AS recent_hires
FROM employees
WHERE joining_date > CURRENT_DATE - INTERVAL '2 years'
GROUP BY department_id
HAVING COUNT(*) > 5;

Normalisation to BCNF

First Normal Form (1NF): No repeating groups, each cell contains a single atomic value, each row is unique.

Second Normal Form (2NF): 1NF + no partial dependencies (every non-key attribute depends on the whole primary key, not just part of it). Applicable only when the primary key is composite.

Third Normal Form (3NF): 2NF + no transitive dependencies (non-key attributes depend only on the primary key, not on other non-key attributes).

Boyce-Codd Normal Form (BCNF): For every functional dependency A → B, A must be a superkey. Stricter than 3NF - handles anomalies that 3NF misses when there are multiple overlapping candidate keys.

Classic interview example: Table: (StudentID, Course, Teacher) Dependencies: (StudentID, Course) → Teacher, Teacher → Course This is in 3NF but NOT BCNF because Teacher → Course, and Teacher is not a superkey. Decompose: (StudentID, Teacher) and (Teacher, Course).

Transaction Isolation Levels

The four isolation levels address specific concurrency problems:

Isolation Level Dirty Read Non-Repeatable Read Phantom Read
Read Uncommitted Possible Possible Possible
Read Committed Prevented Possible Possible
Repeatable Read Prevented Prevented Possible
Serialisable Prevented Prevented Prevented

Definitions:

  • Dirty Read: Reading uncommitted changes of another transaction that may later be rolled back.
  • Non-Repeatable Read: Reading the same row twice within a transaction and getting different values because another transaction modified and committed between the reads.
  • Phantom Read: Re-executing a query within a transaction and getting additional rows because another transaction inserted and committed between the reads.

The Digital interview question: “When would you use Read Committed vs Repeatable Read?” Read Committed: When you need to avoid dirty reads but can tolerate seeing committed changes from concurrent transactions. Most banking systems use this as a base. Repeatable Read: When a transaction needs consistent data across multiple reads of the same rows. Order processing systems benefit from this.

Indexing Strategies

B-Tree Index: Default index type in most databases. Supports equality, range queries, and ORDER BY. Stored as a balanced tree; search is O(log N).

Hash Index: Only supports equality queries (=). Does not support range queries or ORDER BY. Very fast for exact-match lookups O(1).

Composite Index: An index on multiple columns. Follows the leftmost prefix rule - a composite index on (A, B, C) can be used for queries filtering on A, or on A and B, or on A and B and C, but NOT on B alone or C alone.

Covering Index: An index that contains all columns required by a query. The database can answer the query entirely from the index without accessing the actual table rows. Fastest possible query execution.

When NOT to index: Small tables (full table scan is faster), columns with very low cardinality (boolean, gender - the index has too few distinct values to be selective), columns that are very frequently updated (index maintenance overhead).

Stored Procedures vs Functions

Aspect Stored Procedure Function
Return value Can return 0 or multiple values via OUT parameters Must return exactly one value
Can be called from SQL Cannot be called in SELECT statement Can be called in SELECT statement
Transaction control Can contain COMMIT, ROLLBACK Cannot
Primary use Complex business logic, data manipulation Computation that returns a value

Section 4: Operating Systems - Depth Questions

Process Synchronisation

The Critical Section Problem: Multiple processes share a resource. The critical section is the code that accesses the shared resource. Only one process should be in the critical section at a time.

Requirements for a valid solution:

  1. Mutual exclusion: At most one process in the critical section at a time.
  2. Progress: If no process is in the critical section and some processes want to enter, one of them must be allowed to enter in finite time.
  3. Bounded waiting: There exists a bound on the number of times other processes enter the critical section after a process has requested entry, before that request is granted.

Semaphores:

  • Binary semaphore (mutex): values 0 or 1. P(wait): decrement if > 0, else block. V(signal): increment, wake a blocked process.
  • Counting semaphore: integer value, used for resource pools.

Producer-Consumer with semaphores:

Semaphores: mutex=1, empty=N (buffer size), full=0

Producer:
    wait(empty)   // wait for empty slot
    wait(mutex)   // acquire lock
    produce item
    signal(mutex) // release lock
    signal(full)  // signal item available

Consumer:
    wait(full)    // wait for item
    wait(mutex)   // acquire lock
    consume item
    signal(mutex) // release lock
    signal(empty) // signal empty slot

Deadlock conditions (all four must hold simultaneously):

  1. Mutual Exclusion: Resources cannot be shared simultaneously.
  2. Hold and Wait: A process holds at least one resource and waits for more.
  3. No Preemption: Resources cannot be taken from a process without its cooperation.
  4. Circular Wait: P1 waits for P2’s resource, P2 waits for P3’s, P3 waits for P1’s.

Banker’s Algorithm: A deadlock avoidance algorithm. Before granting a resource request, the algorithm checks whether granting the request would leave the system in a “safe state” (a state where there exists a sequence in which all processes can complete). If not safe, the request is deferred.

Digital interview follow-up: “Can you trace through a simple Banker’s algorithm example?” This requires: Maximum matrix, Allocated matrix, Need = Maximum - Allocated, Available vector. Find a safe sequence by identifying processes whose needs can be satisfied by current available resources, run them, add their resources back, and repeat.

Virtual Memory and Paging

Key concepts:

  • Virtual address space is divided into fixed-size pages.
  • Physical memory is divided into frames of the same size.
  • Page table maps virtual page numbers to physical frame numbers.
  • TLB (Translation Lookaside Buffer): Hardware cache for page table entries. Speeds address translation from O(memory access) to near-O(1).

Page fault: A process accesses a virtual page not currently in physical memory. The OS must load the page from disk into a free frame, update the page table, and restart the instruction. Page faults are extremely expensive (disk I/O).

Page replacement algorithms:

  • FIFO: Replace the oldest loaded page. Simple but may exhibit Belady’s anomaly (more frames → more page faults).
  • LRU: Replace the page not used for the longest time. Better approximation of optimal but expensive to implement exactly.
  • Optimal: Replace the page that will not be used for the longest time in the future. Optimal in theory but requires knowing the future - used as a benchmark.

Calculation example: With 3 frames and reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5: Under FIFO: Count page faults by tracing frame state after each access. Frame state: [1], [1,2], [1,2,3], 2,3,4, 3,4,1, 4,1,2, 1,2,5, 1,2,5, 1,2,5, 2,5,3, 5,3,4, 3,4,5 = 9 page faults.

Linux Commands at Digital Level

Digital candidates are expected to know practical Linux commands beyond ls, cd, pwd:

Process management:

  • ps aux: show all running processes with CPU and memory usage.
  • kill -9 PID: forcefully terminate a process.
  • top / htop: interactive process monitor.
  • nice -n 10 command: run command with lower priority.
  • nohup command &: run command immune to hangups, in background.

File and text processing:

  • grep -r "pattern" /path: recursively search for pattern in files.
  • grep -n "pattern" file: show line numbers of matches.
  • awk '{print $2}' file: print second field of each line.
  • sed 's/old/new/g' file: replace all occurrences of “old” with “new”.
  • wc -l file: count lines in file.
  • sort file | uniq -c: sort and count unique lines.

Network:

  • netstat -an: show all active network connections.
  • curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' http://url: make a POST request.
  • wget URL: download file from URL.
  • ping -c 4 host: ping host 4 times.
  • traceroute host: trace network path to host.

System:

  • df -h: disk space usage in human-readable format.
  • du -sh /path: size of directory.
  • free -m: memory usage in megabytes.
  • chmod 755 file: set file permissions (owner: rwx, group: r-x, others: r-x).
  • chown user:group file: change file ownership.
  • tar -czvf archive.tar.gz /path: create compressed archive.
  • tar -xzvf archive.tar.gz: extract compressed archive.
  • crontab -e: edit scheduled tasks (cron jobs).

Section 5: Computer Networks - TCP and REST

The TCP Three-Way Handshake

TCP establishes a connection using three messages:

  1. SYN (Client → Server): Client sends a segment with SYN flag set and a random Initial Sequence Number (ISN) X. “I want to connect; my sequence starts at X.”

  2. SYN-ACK (Server → Client): Server sends SYN-ACK with its own ISN Y, and acknowledges the client’s SYN with ACK = X+1. “I accept; my sequence starts at Y; I acknowledge your X.”

  3. ACK (Client → Server): Client sends ACK = Y+1. “I acknowledge your Y.” Connection established.

Connection termination (four-way): FIN → ACK → FIN → ACK. The extra step exists because each direction closes independently. One side can stop sending while the other still has data to send.

Why three-way and not two-way: Two messages would only allow one side to establish its ISN. Three messages allow both sides to establish their ISNs and acknowledge each other’s, enabling full-duplex reliable communication.

HTTP Methods and REST

HTTP Methods (not just GET and POST):

  • GET: Retrieve a resource. Idempotent. No body in request.
  • POST: Create a resource. Not idempotent. Body contains new resource data.
  • PUT: Replace a resource entirely. Idempotent. Body contains complete updated resource.
  • PATCH: Partially update a resource. Not necessarily idempotent. Body contains the changes.
  • DELETE: Remove a resource. Idempotent.
  • HEAD: Same as GET but returns only headers, not body. Used to check if a resource exists.
  • OPTIONS: Returns the HTTP methods supported for a resource. Used for CORS preflight.

REST principles:

  1. Stateless: Each request contains all information needed; no session state on server.
  2. Resource-based: URLs represent nouns (resources), HTTP methods represent verbs (actions).
  3. Uniform interface: Consistent API design across all endpoints.
  4. Client-Server separation: Frontend and backend are independent.
  5. Cacheable: Responses should indicate whether they can be cached.

RESTful URL design:

  • GET /users - list all users
  • POST /users - create a user
  • GET /users/123 - get user 123
  • PUT /users/123 - replace user 123
  • DELETE /users/123 - delete user 123
  • GET /users/123/orders - get orders for user 123

HTTP status codes:

  • 2xx: Success (200 OK, 201 Created, 204 No Content)
  • 3xx: Redirection (301 Moved Permanently, 304 Not Modified)
  • 4xx: Client error (400 Bad Request, 401 Unauthorised, 403 Forbidden, 404 Not Found, 409 Conflict)
  • 5xx: Server error (500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable)

DNS Resolution Process

When you type “www.google.com” in a browser:

  1. Browser checks its DNS cache. If found, done.
  2. OS checks its DNS cache and /etc/hosts file. If found, done.
  3. OS queries the configured DNS resolver (usually the ISP’s DNS server).
  4. DNS resolver checks its cache. If found, returns to OS. If not:
  5. DNS resolver queries a root nameserver (one of 13 root server clusters globally).
  6. Root nameserver returns the authoritative nameserver for .com.
  7. DNS resolver queries the .com TLD nameserver.
  8. TLD nameserver returns the authoritative nameserver for google.com.
  9. DNS resolver queries Google’s authoritative nameserver.
  10. Authoritative nameserver returns the IP address for www.google.com.
  11. DNS resolver caches the result and returns it to the OS.
  12. OS returns the IP to the browser.
  13. Browser makes the HTTP connection to the IP address.

The entire process typically takes 50-200ms. The caching at each level prevents repeating the full process for each request.


Section 6: OOP Design - SOLID Principles and Patterns

SOLID Principles with Code Examples

S - Single Responsibility Principle (SRP): A class should have only one reason to change. If a class handles both data storage and email notifications, changes to the email system require modifying the storage class - a violation of SRP.

Violation: UserManager class that handles user creation, password hashing, AND sending welcome emails. Fix: Separate into UserRepository (data), PasswordService (hashing), EmailService (notifications).

O - Open/Closed Principle (OCP): Classes should be open for extension but closed for modification. Add new functionality by extending, not by modifying existing code.

Violation: An AreaCalculator with a big if-else chain checking shape types to calculate area. Adding a new shape requires modifying the calculator. Fix: Define a Shape interface with calculateArea(). Each shape class implements it. The calculator calls shape.calculateArea() without knowing the type.

L - Liskov Substitution Principle (LSP): Objects of a subclass should be substitutable for objects of the parent class without breaking the program.

Classic violation: Square extends Rectangle. If setWidth(5) on a Square also sets height to 5 (to maintain squareness), code that expects width and height to be independent after setWidth will break. Square is NOT a proper substitute for Rectangle in all contexts despite the mathematical is-a relationship.

I - Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces they do not use. Large interfaces should be split into smaller, specific ones.

Violation: A Worker interface with work() and eat(). A RobotWorker implements Worker but has no need for eat(). Force implementing unused methods = ISP violation. Fix: Workable interface with work(), Eatable interface with eat(). Humans implement both; robots only implement Workable.

D - Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules. Both should depend on abstractions.

Violation: OrderService directly creates MySQLDatabase objects. Switching databases requires modifying OrderService. Fix: OrderService depends on a DatabaseInterface. MySQLDatabase and PostgreSQLDatabase implement DatabaseInterface. OrderService receives a DatabaseInterface via constructor injection.

Design Patterns

Singleton Pattern: Ensures a class has exactly one instance.

public class ConfigManager {
    private static ConfigManager instance;
    private ConfigManager() {}  // private constructor
    public static synchronized ConfigManager getInstance() {
        if (instance == null) instance = new ConfigManager();
        return instance;
    }
}

Use cases: Logger, configuration manager, connection pool manager.

Factory Pattern: Creates objects without specifying the exact class to create.

interface Shape { double area(); }
class Circle implements Shape { ... }
class Square implements Shape { ... }

class ShapeFactory {
    public static Shape create(String type) {
        if (type.equals("circle")) return new Circle();
        if (type.equals("square")) return new Square();
        throw new IllegalArgumentException("Unknown shape: " + type);
    }
}

Observer Pattern: Defines a one-to-many dependency so that when one object changes state, all dependents are notified. Used in event systems.

Strategy Pattern: Defines a family of algorithms, encapsulates each one, and makes them interchangeable.

interface SortStrategy { void sort(int[] array); }
class BubbleSortStrategy implements SortStrategy { ... }
class QuickSortStrategy implements SortStrategy { ... }

class Sorter {
    private SortStrategy strategy;
    public Sorter(SortStrategy strategy) { this.strategy = strategy; }
    public void sort(int[] array) { strategy.sort(array); }
}

Section 7: System Design Basics for Freshers

Digital freshers are not expected to design production-grade distributed systems. They are expected to understand the basic building blocks and articulate trade-offs.

Load Balancing

A load balancer distributes incoming requests across multiple servers to prevent any single server from becoming a bottleneck.

Algorithms:

  • Round-robin: Requests distributed to servers in sequence (1→2→3→1→2→3…). Simple but ignores server load.
  • Weighted round-robin: Servers with higher capacity receive more requests.
  • Least connections: Route to server with fewest active connections. Better than round-robin when request processing times vary significantly.
  • IP hash: Route based on client IP hash. Ensures the same client always reaches the same server (session persistence without shared session store).

Why it matters: A single server handling all requests becomes a single point of failure. With load balancing, if one server fails, the load balancer routes around it. Horizontal scaling (adding more servers) becomes straightforward.

Caching

Caching stores frequently accessed data in a faster storage layer to reduce latency and database load.

Cache placement options:

  • Client-side cache: Browser cache, mobile app cache. Reduces network requests entirely.
  • CDN (Content Delivery Network): Cache static assets geographically close to users. Reduces latency for global users.
  • Application-level cache: In-memory cache (Redis, Memcached) between the application and database. Dramatically reduces database queries for frequently read data.
  • Database cache: Query result cache at the database level.

Cache eviction policies: LRU (Least Recently Used), LFU (Least Frequently Used), FIFO.

Cache consistency challenges: When the underlying data changes, cached data becomes stale. Solutions: TTL (Time To Live - cache entries expire after a set duration), write-through (update cache and database simultaneously on every write), write-back (update cache immediately, database asynchronously).

The interviewer question: “What problem does caching solve, and what problem does it introduce?” Solves: Latency and database load. Introduces: Cache consistency - stale data can be served to users. The famous saying: “There are only two hard things in computer science: cache invalidation and naming things.”

Database Sharding

Sharding divides a large database horizontally across multiple servers (shards). Each shard contains a subset of the data.

Sharding strategies:

  • Range-based: Shard 1 stores user IDs 1-1,000,000. Shard 2 stores 1,000,001-2,000,000. Simple but uneven distribution if some ranges are accessed far more than others.
  • Hash-based: shard_id = hash(user_id) % number_of_shards. Even distribution but adding shards requires rehashing.
  • Directory-based: A lookup table maps data keys to shards. Flexible but the lookup table is a single point of failure and bottleneck.

Why sharding matters: A single database server has hardware limits (CPU, memory, disk I/O). When a dataset or request volume exceeds these limits, vertical scaling (bigger hardware) becomes prohibitively expensive. Sharding allows horizontal scaling by distributing both data and request load.

The trade-off: Cross-shard queries (queries that need data from multiple shards) are expensive. Schema that requires frequent cross-shard joins is poorly suited for sharding.


50+ Interview Questions by Category

Data Structures (15 Questions)

Q1: Implement a queue using two stacks. Approach: Stack1 for enqueue, Stack2 for dequeue. When dequeue is needed and Stack2 is empty, pop all from Stack1 onto Stack2.

Q2: Find the middle element of a linked list in one pass. Approach: Two pointers - slow moves 1 step, fast moves 2 steps. When fast reaches end, slow is at middle.

Q3: Detect if a linked list has a cycle. Approach: Floyd’s cycle detection (tortoise and hare).

Q4: Reverse a linked list iteratively. Approach: Three pointers: prev=null, curr=head, next=null. For each node, save next, point curr.next to prev, advance both.

Q5: Find if a binary tree is balanced. Approach: Recursive height function that returns -1 if unbalanced. A tree is balanced if |height(left) - height(right)| ≤ 1 for every node.

Q6: Level-order traversal of a binary tree. Approach: BFS with a queue. At each level, process all nodes in the queue.

Q7: Implement a min-stack that supports push, pop, and getMin in O(1). Approach: Maintain a second “min stack” that tracks the minimum at each state.

Q8: Find the longest palindromic substring. Approach: Expand around each centre (odd length) and each pair of centres (even length). O(N²) time, O(1) space.

Q9: Check if a binary tree is a valid BST. Approach: Pass min and max bounds in recursive calls. Each node must be within (min, max).

Q10: Find the k-th smallest element in a BST. Approach: In-order traversal (which gives sorted order in a BST) with a counter. When counter reaches k, return current node.

Q11: Merge two sorted linked lists. Approach: Compare heads, take the smaller, recurse on the rest.

Q12: Clone a graph (deep copy). Approach: BFS/DFS with a HashMap mapping original nodes to cloned nodes.

Q13: Find all paths from root to leaves in a binary tree. Approach: DFS with a path accumulator. When a leaf is reached, add the path to results.

Q14: Implement a trie (prefix tree) with insert and search. Approach: Each node has a HashMap<Character, TrieNode> for children and a boolean isEndOfWord.

Q15: Find the diameter of a binary tree (longest path between any two nodes). Approach: For each node, the diameter passing through it = left height + right height. Track global maximum.

DBMS (10 Questions)

Q16: Write a query to find all customers who placed more orders than the average.

SELECT customer_id, COUNT(*) as order_count
FROM orders
GROUP BY customer_id
HAVING COUNT(*) > (SELECT AVG(order_count) FROM (SELECT COUNT(*) as order_count FROM orders GROUP BY customer_id) avg_table);

Q17: What is a covering index? Give an example. Answer: An index that contains all columns referenced in a query, so the query can be satisfied entirely from the index without accessing the table. Example: Query SELECT name, age FROM users WHERE email = 'x'. A covering index on (email, name, age) means no table access is needed.

Q18: Explain MVCC (Multi-Version Concurrency Control). Answer: Rather than locking rows for reading, MVCC keeps multiple versions of each row. Readers see a consistent snapshot from a point in time; writers create new versions. This allows readers and writers to proceed concurrently without blocking each other.

Q19: What is an N+1 query problem? Answer: When fetching N objects, the code executes 1 query to fetch the list and then N additional queries to fetch associated data for each object. Total: N+1 queries. Solution: use JOIN or eager loading to fetch everything in 1-2 queries.

Q20: Difference between TRUNCATE and DELETE with WHERE. Answer: TRUNCATE removes all rows without scanning them individually (DDL operation, cannot be rolled back in most databases, resets auto-increment). DELETE with WHERE scans rows and removes matching ones (DML, can be rolled back, does not reset auto-increment).

Q21: What is a deadlock in a database context and how does the DBMS handle it? Answer: When two transactions each hold a lock the other needs, both wait indefinitely. DBMS handles this by deadlock detection (cycle detection in the wait-for graph) and victim selection (one transaction is rolled back, releasing its locks, allowing the other to proceed).

Q22: Explain the difference between optimistic and pessimistic locking. Answer: Pessimistic locking locks a record when it is read, preventing others from modifying it until the lock is released. Suitable when conflicts are frequent. Optimistic locking assumes conflicts are rare - reads without locking, but before writing, checks if the record has been modified by another transaction (using a version number or timestamp). If modified, the update is rejected and the transaction is retried.

Q23: Write SQL to pivot rows into columns. Answer: Using conditional aggregation: SELECT user_id, SUM(CASE WHEN product='A' THEN amount ELSE 0 END) as A_sales, SUM(CASE WHEN product='B' THEN amount ELSE 0 END) as B_sales FROM sales GROUP BY user_id;

Q24: What is a materialized view and when is it useful? Answer: A materialized view stores the result of a query physically (like a table). Unlike a regular view (which re-executes the query on each access), a materialized view is precomputed and can be indexed. Useful for expensive aggregation queries that are accessed frequently but whose underlying data changes infrequently.

Q25: How does B-tree indexing work internally? Answer: B-trees are self-balancing tree structures where each node contains multiple keys and pointers. Keys in each node are sorted. Search starts at the root, compares the search key with node keys to choose the appropriate child pointer, and traverses down to a leaf. The tree stays balanced through splits when nodes overflow. Height is O(log N), guaranteeing O(log N) search time.

Operating Systems (10 Questions)

Q26: What is the difference between a process and a thread? Answer: A process is an independent program with its own memory space, file descriptors, and system resources. A thread is a lightweight execution unit within a process, sharing the process’s memory and resources. Multiple threads within a process can communicate directly through shared memory; multiple processes must use IPC (pipes, sockets, shared memory segments). Context switch between threads is faster than between processes.

Q27: What are zombie and orphan processes? Answer: A zombie process has completed execution but its entry remains in the process table because the parent has not yet called wait() to collect the exit status. An orphan process is still running but its parent has terminated; it is adopted by the init process (PID 1) which eventually calls wait() on it.

Q28: Explain virtual memory and why it allows programs larger than physical RAM to run. Answer: Virtual memory creates the illusion of a large, contiguous address space for each process, abstracting away the actual physical memory layout. Only the actively used pages need to be in RAM; inactive pages are stored on disk (swap space). When a needed page is not in RAM (page fault), it is loaded from disk at the cost of a page fault penalty. This allows programs to use more memory than physically available, though with performance degradation when heavy swapping occurs.

Q29: What is context switching and what is its cost? Answer: Context switching is the process of saving the state (registers, program counter, memory maps) of the currently running process/thread and restoring the state of the next one to run. Cost: the CPU time spent saving and restoring state (itself just a few microseconds) plus the indirect cost of cache pollution - the new process’s data must be loaded into CPU caches, evicting the previous process’s data. Heavy context switching wastes a significant fraction of CPU time on overhead rather than useful work.

Q30: Explain the differences between mutex, semaphore, and monitor. Answer: A mutex is a binary lock that allows only the acquiring thread to release it (ownership-based). A semaphore is a signalling mechanism with a count; any thread can call signal (V) regardless of which called wait (P) - useful for signalling between producers and consumers. A monitor is a higher-level synchronisation construct that combines a mutex with condition variables, providing a way to wait for specific conditions while holding a lock. Java’s synchronized keyword implements monitor-style synchronisation.

Q31: What is a race condition and how do you prevent it? Answer: A race condition occurs when the behaviour of a program depends on the relative timing of operations in concurrent threads. If two threads both read and modify the same variable without synchronisation, the final value depends on which thread executes last - unpredictable. Prevention: use synchronisation mechanisms (mutex, atomic operations, or thread-safe data structures) to ensure only one thread accesses the critical section at a time.

Q32: What is demand paging? Answer: Demand paging loads pages into memory only when they are referenced (on demand), rather than loading all pages at program start. When a page is first accessed, a page fault occurs, the OS loads the page from disk, and execution resumes. This reduces startup time and memory usage for programs with large codebases but small working sets.

Q33: Describe the Readers-Writers problem. Answer: Multiple readers can access shared data simultaneously. Writers require exclusive access (no other readers or writers). The challenge: balance writer starvation (if readers continuously arrive, writers never get access) against reader starvation (if writers have priority, readers may wait indefinitely). Solutions include giving preference to either readers or writers, or using a fair algorithm that services requests in arrival order.

Q34: What is memory fragmentation? Answer: External fragmentation: free memory exists but is scattered in small non-contiguous blocks too small to satisfy large allocation requests. Internal fragmentation: allocated memory is larger than what was requested (due to alignment or fixed block sizes), wasting memory within allocations. Solutions: compaction (move allocations to coalesce free space), buddy system (power-of-2 sized blocks that merge efficiently), slab allocation (pre-allocated pools of same-sized objects).

Q35: Explain the fork() system call. Answer: fork() creates a child process that is an almost exact copy of the parent: same program counter, same file descriptors, same memory content (via copy-on-write). fork() returns 0 in the child and the child’s PID in the parent. This allows both to continue executing from the same point. The child typically calls exec() to replace its image with a new program. Together, fork() + exec() is the standard Unix way of creating new processes.

Computer Networks (10 Questions)

Q36: Explain the OSI model layers. Answer: 7 layers from bottom to top: Physical (bits, wires), Data Link (frames, MAC addresses, error detection), Network (packets, IP routing), Transport (segments, TCP/UDP, end-to-end reliability), Session (session management), Presentation (data format, encryption/compression), Application (HTTP, FTP, SMTP - user-facing protocols).

Q37: What is the difference between TCP and UDP? Answer: TCP: connection-oriented, reliable (acknowledgements, retransmission), ordered delivery, flow control, congestion control. Overhead: 3-way handshake, headers, acknowledgement traffic. Use: web browsing, email, file transfer. UDP: connectionless, no reliability guarantee, no ordering guarantee. Lower overhead and latency. Use: video streaming, online gaming, DNS, VoIP (where some packet loss is acceptable but latency must be low).

Q38: What is a subnet mask and how does it work? Answer: A subnet mask identifies which portion of an IP address is the network address and which is the host address. Example: IP 192.168.1.10 with mask 255.255.255.0 (or /24). The first 3 octets (192.168.1) are the network; the last octet (10) identifies the host. The network can have 254 hosts (0 is network address, 255 is broadcast). Subnetting divides a larger network into smaller segments for security and traffic management.

Q39: Explain HTTPS and TLS handshake. Answer: HTTPS = HTTP over TLS (Transport Layer Security). TLS handshake: Client sends ClientHello (supported cipher suites, TLS versions). Server responds with ServerHello (chosen cipher suite), its certificate (containing its public key). Client verifies the certificate against trusted CAs. Client generates a pre-master secret, encrypts it with the server’s public key, sends it. Both sides derive session keys from the pre-master secret. Both send “Finished” messages encrypted with session keys. All subsequent HTTP traffic is encrypted with session keys.

Q40: What is NAT (Network Address Translation)? Answer: NAT allows multiple devices on a private network to share a single public IP address. The NAT device (typically a router) maintains a translation table mapping internal private IP:port pairs to the external public IP:port. Outgoing packets have their source address rewritten; incoming packets have their destination address rewritten based on the table. This extends IPv4 addressing (which has an address shortage) and provides some security by hiding internal network structure.

OOP Design (5 Questions)

Q41: Design a parking lot system. What classes would you create? Answer: ParkingLot (manages floors, entry/exit), ParkingFloor (manages spots), ParkingSpot (stores vehicle, type: compact/large/handicapped), Vehicle (type, plate number), Ticket (entry time, spot reference, vehicle), PaymentSystem. Relationships: ParkingLot has many ParkingFloors, ParkingFloor has many ParkingSpots, Ticket references a ParkingSpot and a Vehicle.

Q42: Explain the Decorator pattern with an example. Answer: Decorator adds behaviour to objects dynamically without changing their class. Example: a TextMessage class, decorated by EncryptedMessage (adds encryption), CompressedMessage (adds compression). Decorators wrap the original object and forward calls, adding their behaviour. This avoids class explosion from all combinations of text+encrypted+compressed etc.

Q43: When would you use composition over inheritance? Answer: “Prefer composition over inheritance” (from Gang of Four). Inheritance creates tight coupling - subclasses depend on parent implementation details. Composition allows swapping behaviours at runtime, does not expose parent internals, and avoids the fragile base class problem. Use inheritance for is-a relationships where the subclass truly is a more specific type of the parent and shares its public interface semantics. Use composition for has-a relationships or when behaviour needs to vary independently.

Q44: What is method overloading vs overriding? Which is resolved at compile time? Answer: Overloading: multiple methods with the same name but different parameter lists in the same class. Resolved at compile time (static dispatch). Overriding: subclass provides a specific implementation of a method already defined in the parent class. Resolved at runtime (dynamic dispatch, polymorphism). This is why @Override annotation is useful - it ensures you are actually overriding and not accidentally overloading.

Q45: Explain the difference between abstract class and interface in Java. Answer: Already covered in the ILP Java article, but at Digital interview depth: An abstract class can have constructors, fields, and both abstract and concrete methods. It models an is-a relationship with shared implementation. An interface defines a contract (what a class can do) without implementation (except default methods in Java 8+). A class can implement multiple interfaces but extend only one abstract class. When designing: use abstract class when you want to share code among related classes; use interface when unrelated classes should share a behaviour contract.


The HR + Coding Hybrid Round

What Makes the Digital HR Round Different

The Digital HR round is not purely HR - it is a competency validation session conducted by a management professional who has been briefed on your technical round performance. Expect:

  • Technical questions framed as scenarios: “Tell me about a complex bug you debugged. How did you isolate the root cause?”
  • Coding problem in casual framing: “Can you write a quick function on paper that reverses words in a sentence?” (This is testing whether your coding fluency holds under less formal conditions.)
  • “Why Digital?” - the core question that all Digital HR rounds include in some form.

Answering “Why Digital?”

This question tests whether you understand what you are applying for. A weak answer mentions salary (never say salary) or vague ambition. A strong answer connects your demonstrated technical capabilities (your Advanced coding performance, your project work) to the technical demands of the Digital profile.

Strong “Why Digital?” framework:

  1. Acknowledge the technical bar: “I understand that Digital profile work involves more complex technical challenges - building systems from scratch rather than maintaining them, working with newer technology stacks, contributing to architectural decisions earlier in my career.”
  2. Connect to your demonstrated capabilities: “In the NQT Advanced coding section, I was able to solve problems at that complexity level, which gave me confidence that this is where I belong technically.”
  3. Articulate what you want to build: “Specifically, I want to work on [domain interest - financial systems, retail platforms, etc.]. Digital roles at TCS are at the intersection of serious engineering and real business impact, which matches how I want to grow my career.”

STAR Framework for Behavioural Questions

Situation: Set the context briefly (1-2 sentences). Task: What was your specific responsibility or challenge? (1-2 sentences). Action: What did you do? (3-4 sentences - this is the core of your answer). Result: What happened as a result? (1-2 sentences, include a quantitative result if possible).

Common Digital behavioural questions:

“Tell me about a time you solved a technically challenging problem.”

  • Situation: Final year project developing X.
  • Task: Needed to optimise a query that was taking 45 seconds to run.
  • Action: Profiled the query, identified missing indexes, restructured the JOIN order based on selectivity, added a composite index on the most selective filter columns.
  • Result: Query time reduced to 1.2 seconds. Project deadline met, professor noted the optimisation work specifically.

“Tell me about a time you worked with a difficult team member.”

  • Situation/Task: Group project where one member was not contributing.
  • Action: Had a private conversation to understand if there was a blocker. Discovered they were struggling with the frontend framework. Paired with them for two sessions to get them up to speed.
  • Result: Member contributed meaningfully in the final two weeks. Project submitted on time with complete feature set.

Mock Interview Simulation Framework

The Self-Interview Protocol

Without a preparation partner, simulate the interview using this framework:

Setup: Choose a specific topic (e.g., “Binary Trees”). Set a 20-minute timer. Open a blank document.

Step 1: State the topic and write 3 questions you would expect on that topic if you were the interviewer.

Step 2: Write your answers to each question in full, as if speaking out loud. Include: the definition, a code example or pseudocode, the time complexity, a real-world use case, and one common mistake.

Step 3: Review your answers against this guide. Where did you skip complexity analysis? Where did you forget edge cases? Where was the explanation unclear?

Step 4: Re-answer the weakest question from Step 2, incorporating what you missed.

Repeating this protocol for 5 topics gives you deep, examined knowledge of 15+ specific questions and reveals the exact gaps in your explanation quality before the interview.

Communication Quality Checklist

Before the interview, verify these communication habits through the self-interview protocol:

  • Do you define terms before using them? (“A BST, which is a Binary Search Tree where every left child’s value is less than the parent…”)
  • Do you quantify complexity after every algorithm? (“This runs in O(N log N) time due to the sorting step…”)
  • Do you mention edge cases proactively? (“This handles the empty input case by returning null…”)
  • Do you ask clarifying questions before answering? (“Before I answer, can I confirm that the array may contain negative numbers?”)
  • Can you explain the trade-off between two approaches without prompting? (“The linked list approach uses O(N) space but gives O(1) insertion; the array approach uses O(1) space but O(N) insertion…”)

These habits separate Digital-calibre candidates from Ninja-calibre candidates in the interview room, independent of technical knowledge depth.


Frequently Asked Questions: TCS Digital Interview

How many rounds does the Digital interview have? Typically two rounds: Technical (60-90 minutes) and HR/Management (30-45 minutes). Some hiring cycles include an additional preliminary technical screening. Your invitation email will specify the expected format for your specific batch.

Will I be asked to write code on paper? Almost certainly yes. The Digital Technical round expects at least one coding problem where you write code on paper or describe it in detail verbally. Practice writing code without autocomplete by doing at least 5 coding sessions on paper in the week before your interview.

How deep should my project explanation be? Deep enough to answer “why did you make that technical decision?” for every component. If you used a MySQL database, know why you chose MySQL over PostgreSQL or MongoDB. If you used a REST API, know why REST rather than GraphQL or SOAP. If you used an ORM, know what problem it solves and what overhead it introduces.

What if I am asked about a topic I have not studied (e.g., a specific OS algorithm)? Be honest but demonstrate reasoning ability: “I haven’t studied the Banker’s Algorithm specifically, but from your description, it sounds like a form of state-space search where the system checks if granting a resource request leads to a state with a valid completion sequence. Is that roughly right?” This shows intellectual engagement and honest self-assessment - far better than guessing incorrectly or going completely silent.

Should I prepare system design for a Digital fresher interview? Know the concepts at awareness level: what load balancing does, what caching is and the consistency challenge it introduces, what sharding does. You will not be asked to design a Twitter-scale system. You may be asked “how would you scale your final year project if it needed to handle 1 million users?” That question is answered with: “Add a load balancer, move sessions to a distributed cache like Redis, add read replicas for the database, consider sharding if the data grows very large.” The vocabulary and high-level concepts are the bar for freshers.


Extended Question Bank: 25 Additional Technical Questions

Advanced Data Structures (5 More)

Q46: Explain the difference between DFS and BFS, and when you would choose each. Answer: DFS (Depth-First Search) explores as far down a branch as possible before backtracking. Uses a stack (or recursion). Good for: topological sort, finding all paths, detecting cycles, solving maze problems, exploring all states in a game tree. Memory usage: O(H) where H is the depth.

BFS (Breadth-First Search) explores all neighbours at the current depth before going deeper. Uses a queue. Good for: finding the shortest path in an unweighted graph, level-order tree traversal, finding nodes closest to a source. Memory usage: O(W) where W is the maximum width.

Choose DFS when you need to visit all nodes and depth-first order matters (topological sort, tree DFS). Choose BFS when you need the shortest path or level-by-level processing.

Q47: What is a heap and how does it differ from a BST? Answer: A heap is a complete binary tree (all levels filled except possibly the last, filled left to right) satisfying the heap property: in a min-heap, every parent is smaller than or equal to its children; in a max-heap, every parent is larger. Heaps are implemented as arrays (parent at index i, children at 2i+1 and 2i+2).

BST vs Heap: BST maintains sorted order for all subtrees (left < parent < right), supporting O(log N) search. Heap only maintains the partial order needed for efficient min/max extraction - you can find the minimum in O(1), but searching for an arbitrary element requires O(N). Heaps are optimal for priority queues; BSTs are optimal for ordered data with search requirements.

Q48: Implement a Trie for autocomplete. What is its advantage over a HashMap? Answer: A trie stores strings in a tree where each node represents a character. The path from root to a node spells a prefix. Insert and search are O(L) where L is the string length, same as a HashMap. The advantage: a trie supports prefix queries. “Find all strings starting with ‘com’” is O(length of prefix + number of results) in a trie, versus O(total number of strings) in a HashMap (you must check all keys). Autocomplete, autocorrect, and spell checkers use tries for this reason.

Q49: What is a skip list and what problem does it solve? Answer: A skip list is a probabilistic data structure providing O(log N) average-case operations (search, insert, delete) for a sorted sequence. Unlike a balanced BST, it achieves this without complex rotation operations. It uses multiple levels of linked lists with decreasing node density at higher levels, allowing searches to skip over many nodes. The trade-off: more memory than a simple linked list, but faster than O(N) sequential search. Redis uses skip lists for its sorted sets.

Q50: Explain consistent hashing and why it is used in distributed systems. Answer: In a standard hash table with N servers, adding or removing a server causes almost all keys to be remapped (hash(key) % N changes for almost all keys). For a distributed cache, this means a cache miss storm when servers are added or removed.

Consistent hashing maps both servers and keys onto a ring (circular hash space). A key is stored on the first server encountered clockwise on the ring. When a server is added or removed, only the keys it was responsible for (clockwise neighbours) are remapped - on average N/K keys, where N = total keys and K = new server count, not all keys. This minimises the disruption from topology changes. Used in Cassandra, Amazon Dynamo, and distributed caches like Memcached.

SQL Advanced (5 More)

Q51: What is the difference between a correlated and non-correlated subquery? Answer: A non-correlated subquery is independent - it executes once and its result is used by the outer query. SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees) - the subquery runs once.

A correlated subquery references the outer query and must execute once per row of the outer query. SELECT e.name FROM employees e WHERE e.salary > (SELECT AVG(salary) FROM employees WHERE department_id = e.department_id) - the subquery executes once per employee row, each time with a different e.department_id. Correlated subqueries are powerful but potentially slow; they can often be rewritten as JOINs for better performance.

Q52: Write a query to find duplicate records in a table.

SELECT email, COUNT(*) as count
FROM users
GROUP BY email
HAVING COUNT(*) > 1;

-- To see the full duplicate rows:
SELECT *
FROM users
WHERE email IN (
    SELECT email FROM users GROUP BY email HAVING COUNT(*) > 1
)
ORDER BY email;

Q53: What is the N+1 SELECT problem in ORMs and how do you fix it? Answer: When using an ORM to retrieve a list of parent objects and then accessing their child objects, the ORM executes 1 query for the parents and N additional queries for the children (one per parent). Total: N+1 queries. Fix: Use eager loading (JOIN FETCH in JPA, includes in ActiveRecord, select_related in Django ORM). This fetches parents and children in a single JOIN query or a small number of queries, reducing database round-trips from N+1 to 1 or 2.

Q54: Explain database denormalisation and when it is appropriate. Answer: Normalisation removes data redundancy. Denormalisation intentionally introduces redundancy to improve read performance. Example: instead of joining orders, customers, and products tables for every order report, store a flattened order_summary table with customer name and product name pre-joined. Reads become simpler and faster; writes require maintaining consistency in multiple places.

Appropriate when: read-heavy workloads where join performance is a bottleneck, when complex joins are prohibitively expensive, in reporting databases or data warehouses where data is loaded periodically and then only read.

Q55: What is query optimisation and what does an EXPLAIN plan tell you? Answer: Query optimisation is the process by which the database’s query planner chooses the most efficient execution strategy. EXPLAIN (or EXPLAIN ANALYZE in PostgreSQL) shows the execution plan: which index is used (or if a full table scan occurs), the estimated row counts, the join algorithms chosen (nested loop, hash join, merge join), and the estimated cost.

Key things to look for in an EXPLAIN plan: Full table scans on large tables (should usually use an index), nested loop joins on large result sets (hash joins are more efficient for large datasets), very high estimated row counts diverging from actual (statistics may be stale - run ANALYZE).

OS and Networks (10 More)

Q56: What is the difference between a process in user space and kernel space? Answer: User space is the restricted memory area where application code executes. Processes in user space cannot directly access hardware or kernel data structures. Kernel space is where the OS kernel runs with full hardware access. When an application needs a privileged operation (reading a file, creating a network connection), it makes a system call, which switches execution from user space to kernel space, performs the operation, and switches back. This separation protects the OS from faulty or malicious application code.

Q57: Explain the concept of socket programming. What is the difference between a socket and a port? Answer: A socket is an endpoint for communication identified by an IP address and port number. Socket programming uses OS-provided APIs to create connections (TCP) or send datagrams (UDP).

Basic TCP server pattern: socket()bind(port)listen()accept()read()/write()close(). Basic TCP client pattern: socket()connect(server_ip, port)write()/read()close().

A port is a 16-bit number (0-65535) identifying a specific process or service on a machine. A socket is a specific communication endpoint - the combination of IP address and port that uniquely identifies a connection endpoint.

Q58: What is HTTPS and how does a certificate authority verify identity? Answer: A Certificate Authority (CA) is a trusted third party that issues digital certificates. When a company wants HTTPS, they generate a key pair, create a Certificate Signing Request (CSR) with their public key and domain information, and submit it to a CA. The CA verifies they control the domain (by checking a specific file placed on the web server or a DNS record). If verified, the CA signs the certificate with its own private key. Browsers come pre-installed with a list of trusted CA public keys. When you visit an HTTPS site, your browser verifies the certificate was signed by a trusted CA and that it matches the domain you are visiting.

Q59: What are the differences between synchronous and asynchronous I/O? Answer: Synchronous I/O: The calling thread blocks until the I/O operation completes. Simple programming model but wastes CPU time waiting. Good for I/O operations that complete quickly.

Asynchronous I/O: The calling thread initiates the I/O operation and continues executing other work. When the I/O completes, a callback is invoked or a future/promise resolves. More complex programming model but allows better CPU utilisation - one thread can manage thousands of in-flight I/O operations. Node.js is built on this model (event loop with async I/O). Good for high-concurrency servers handling many simultaneous clients.

Q60: What is a CDN (Content Delivery Network) and how does it work? Answer: A CDN is a geographically distributed network of servers (Points of Presence or PoPs) that cache and serve content from locations close to users. When a user requests a resource, the CDN routes the request to the nearest PoP rather than the origin server (potentially on another continent). This reduces latency (physical distance reduces round-trip time) and reduces load on the origin server.

CDNs are most effective for: static assets (images, JavaScript, CSS), large files (video streaming), and content that changes infrequently. Dynamic content (personalised user data, live data) requires special CDN configurations or always goes to the origin.

Q61: Explain the difference between horizontal and vertical scaling. Answer: Vertical scaling (scale up): Add more resources to a single machine - more CPU, more RAM, faster storage. Simple to implement (no application changes needed), but limited by the maximum single-machine capacity and creates a single point of failure. More expensive per unit of performance at high scales.

Horizontal scaling (scale out): Add more machines and distribute load across them. Theoretically unlimited scalability, no single point of failure, uses commodity hardware. Requires application changes to work across distributed infrastructure (stateless design, distributed data storage). More complex to operate but more flexible.

Q62: What is an API gateway and what problems does it solve? Answer: An API gateway is a single entry point for all client requests to a microservices backend. It handles: routing (directing requests to the appropriate microservice), authentication and authorisation (so each microservice does not need to implement auth), rate limiting, request/response transformation, logging, and monitoring.

Without an API gateway, clients must know the addresses of all microservices and call them individually. Each microservice must implement auth, rate limiting, and logging independently. An API gateway centralises these cross-cutting concerns, simplifying both clients and individual microservices.

Q63: What is the difference between stateful and stateless applications? Answer: A stateful application stores session data (user login state, shopping cart contents) on the server. Any subsequent request from the same user must reach the same server that holds their session. This constrains load balancing (sticky sessions required) and makes scaling complex.

A stateless application stores no session data on the server. All information needed to process a request is contained in the request itself (via tokens, cookies, or request parameters). Any server can handle any request. This enables easy horizontal scaling and load balancing without routing constraints. RESTful APIs are designed to be stateless.

Q64: Explain WebSockets and how they differ from HTTP. Answer: HTTP is a request-response protocol: the client sends a request, the server responds, and the connection closes (or is kept alive for reuse but remains request-initiated). The server cannot push data to the client without a prior request.

WebSockets provide full-duplex communication over a single persistent connection. After the initial HTTP handshake (which upgrades the connection to WebSocket protocol), either side can send messages at any time. This enables real-time features: live chat, collaborative editing, real-time dashboards, online gaming. The connection persists until explicitly closed, unlike HTTP which is stateless and request-driven.

Q65: What is a load balancer and what is the difference between Layer 4 and Layer 7 load balancing? Answer: Layer 4 (Transport layer) load balancing routes based on IP address and port. It does not inspect packet content. Extremely fast, works for any TCP/UDP application.

Layer 7 (Application layer) load balancing routes based on request content - HTTP headers, URLs, cookies. Allows routing /api/* to the API server cluster and /static/* to the CDN. Can implement features like SSL termination, sticky sessions based on cookies, and routing by request type. More processing overhead than Layer 4 but much more flexible.


Body Language and Communication in Technical Interviews

The Technical Communicator’s Checklist

The Digital interview evaluates technical knowledge AND technical communication. These are distinct skills. A candidate who knows the answer but cannot communicate it clearly fails. A candidate who partially knows the answer but communicates their reasoning clearly often succeeds.

Before you answer:

  • Restate the question briefly to confirm understanding: “So you want me to implement a function that takes a linked list and reverses it in-place, returning the new head?”
  • Ask one clarifying question if genuinely needed: “Should I handle the case where the list is empty?”
  • Think aloud about your approach before coding: “My first thought is a three-pointer approach, but let me also consider whether recursion might be cleaner here…”

While you answer:

  • Maintain eye contact during verbal explanations. Looking away while explaining signals uncertainty even when you are correct.
  • Use deliberate pauses rather than filler sounds (“um”, “like”). A 2-second pause for thought communicates confidence; “um um um” for 2 seconds communicates anxiety.
  • Draw diagrams when they help. For linked list reversal, draw the list before and after. Most interviewers appreciate visual aids.
  • Say “I think…” when uncertain rather than asserting incorrect information. “I think the time complexity is O(N log N) because…” signals calibrated confidence.

After you answer:

  • Proactively add complexity analysis: “This solution runs in O(N) time and O(1) space.”
  • Proactively mention edge cases: “I should also consider what happens when the input is empty - my current code returns null, which seems correct.”
  • Invite feedback: “Does that approach make sense, or would you like me to explore an alternative?”

Handling Questions You Cannot Answer

The most important communication skill in the Digital interview is handling knowledge gaps gracefully. Interviewers are not trying to trick you - they are trying to find the edges of your knowledge.

The graceful gap response:

  1. Acknowledge what you do know: “I haven’t worked with Red-Black trees specifically, but I understand the problem they solve - keeping BST height balanced.”
  2. Reason from first principles: “Given that they maintain O(log N) operations, I would guess they must track some kind of balance factor per node, similar to AVL trees, and perform rotations when insertions or deletions would unbalance the tree.”
  3. Ask an engaged question: “Is the key difference between Red-Black and AVL trees in how they define balance, or in the rotation strategy?”

This response demonstrates: honesty (you don’t claim to know what you don’t), reasoning ability (you connect to related knowledge), and intellectual engagement (you ask a genuine question about the topic).

Contrast with: “I don’t know” followed by silence. This provides no information about your reasoning ability and does nothing to advance the interview.

Pace and Clarity

In an anxiety state, candidates tend to speak faster than normal. Fast speech under cognitive load produces unclear explanations. Deliberately slow your pace during technical explanations - use sentences the interviewer can write notes from.

“So what I’m doing here is” - useful transition phrase. “The key insight is” - signals you are about to say something important. “To summarise this approach” - useful before transitioning to complexity analysis. “The trade-off is” - signals you are about to compare options.

These transition phrases slow the pace naturally, make the structure of your answer clear, and buy you thinking time without awkward pauses.


The Night Before and Day Of

Final Preparation (Evening Before Interview)

Technical review (90 minutes maximum): Review the quick-reference card for each major CS topic: DS, Algorithms, DBMS, OS, Networks, OOP. Do not try to learn new topics. Review things you know to keep them fresh.

Review your project: The problem it solved, the architecture, three technical decisions you made and why, one challenge you faced and how you resolved it. This review should take 20-30 minutes.

Prepare your questions for the interviewer (10 minutes): Good questions for TCS Digital interviewers:

  • “What does the first project for Digital joiners typically look like?”
  • “How does the team approach code reviews and technical knowledge sharing?”
  • “What technologies or paradigms does the team use that I might want to start learning before joining?”

These questions signal professional maturity and genuine interest in the work.

Logistics verification:

  • Interview format confirmed (in-person, video, or hybrid)? Video platform tested?
  • Documents prepared (resume printed, ID)?
  • Interview time confirmed and calendar set?
  • Sleep by your regular bedtime - sleep disruption before an interview has a measurable negative effect on cognitive performance.

Day of Interview Execution

Arrive (or connect) 15 minutes early. Use that buffer to breathe slowly, review your project notes one final time, and set your mental state.

When the interview begins, treat the first 2 minutes as a warm-up. The self-introduction is low-stakes - you know this material perfectly. Using that low-stakes time to find your speaking rhythm and eye contact cadence sets up the higher-stakes technical questions that follow.

Every question is answerable with what you know. If you encounter a knowledge gap, use the graceful gap response. If you encounter a question you know well, show depth - give the implementation, the complexity, the trade-off, the edge cases. Demonstrate in every answer that you think at Digital level.

The preparation in this guide, applied consistently across the CS domains covered, produces a candidate who can engage at that level. The interview is not a test of who you are - it is a demonstration of the preparation you have done. Walk in with the confidence that preparation deserves.