SDE2 Interview Questions at TCS
150 real SDE2 interview questions asked at TCS. Covers Technical, System Design, HR, Scenario, Screening rounds. Sourced from engineers who cleared the loop.
Interview Signals — What TCS Asks SDE2s
All SDE2 Questions Asked at TCS
What are the SOLID principles? Explain each with a real-world Java example. Then describe a scenario where rigidly following SOLID leads to over-engineering, and how you balance pragmatism with good design.
A developer puts async code inside useEffect by returning an async arrow function: useEffect(() => async () => {...}). Why is this wrong?
Explain service discovery in microservices. How does Eureka work with Spring Cloud?
Your PostgreSQL query plan shows 'Seq Scan' on a small 1000-row table despite having an index. Why might Postgres choose not to use the index?
What is React.StrictMode and what bugs does it help catch?
Your React app uses React Router. Users report the browser back button doesn't work after programmatic navigation. What are the likely causes?
Explain Docker layer caching. Why do developers often put COPY . . before RUN npm install (wrong) and how to fix it?
What is Spring Boot Actuator? What security risks does it introduce and how do you mitigate them?
Your Node.js API uses async/await throughout. A developer reports that errors thrown in async route handlers are causing the process to crash with 'UnhandledPromiseRejectionWarning'. What's the architectural fix?
Explain how Spring Boot auto-configuration works. How does it know which beans to create?
How does React's useCallback differ from useMemo? A developer uses useCallback everywhere to 'optimize performance.' Is this correct?
Your database has a column with type VARCHAR(255) for email addresses. The column is indexed. Would changing it to VARCHAR(100) improve performance? What about TEXT?
What are Error Boundaries in React and why can't they catch errors in event handlers?
What is the difference between fail-fast and fail-safe iterators in Java Collections? Give examples of collections that use each, explain the ConcurrentModificationException, and show how to safely remove elements during iteration.
Explain CORS. A developer disables CORS entirely with Access-Control-Allow-Origin: * on your API. Why is this a security risk for some endpoints?
You run EXPLAIN on a query and see 'Using index condition' vs 'Using where'. What's the difference and which is better?
Explain the React context API pattern for theming. What is the pitfall when the context value is an object?
You need to process 100,000 CSV rows in Node.js without blocking the event loop and without running out of memory. The file is 2GB. How do you implement this?
Explain how Suspense and lazy loading work together in React for code splitting.
Your Express.js API endpoint returns data in 80ms locally but 800ms in production. Both use the same database. What are the likely causes and how do you systematically investigate?
Explain what HTTPS does and does NOT protect against.
What is CORS and why can't you just 'fix' it by disabling the check in the browser?
You join a team and find the codebase has no tests, no documentation, and deploys manually via FTP. You're asked to build a new feature. How do you approach this?
Your application logs show someone is trying thousands of username/password combinations per second. How do you stop this?
Your Node.js app uses the 'cluster' module with 8 workers. A user's session is stored in memory. Requests from the same user hit different workers randomly. What breaks and how do you fix it?
A user reports they can see another user's data by changing the ID in the URL: /api/orders/123 → /api/orders/124. What vulnerability is this?
A stakeholder shows you conflicting requirements from two different business units. How do you resolve this?
Explain OWASP Top 10 in 2023. Pick 3 and explain how to defend against them with code examples.
Your team needs to migrate a large class component codebase to hooks. A senior dev says 'just convert everything to hooks.' What risks does this carry and how would you approach the migration safely?
Your Express API has a middleware that measures response time. You notice async route handlers are reporting incorrect times (too short). Why?
What is a gap analysis and how would you conduct one for a company migrating from an old CRM to Salesforce?
Your company stores user passwords as MD5 hashes. A developer says 'MD5 is fine because we also add a salt.' Is he right? Explain the actual risk and the correct solution.
You're gathering requirements for a new feature. The client says 'I want something like Amazon's recommendation system.' How do you handle this vague requirement?
Your API returns different error messages for valid vs invalid usernames during login (e.g., 'Wrong password' vs 'User not found'). Why is this a security vulnerability and how do you fix it?
Explain the difference between functional and non-functional requirements. Give 5 examples of each for a banking application.
Your React component tree is 8 levels deep. A state change at level 1 needs to reach a component at level 8. Without Redux or Context, you're prop drilling through 6 intermediate components. What are your options?
You're a new BA joining a project that's 6 months in. How do you quickly get up to speed without disrupting the team?
Explain the SOLID principles in software design. Give a real code example of violating Single Responsibility Principle.
A product manager reports that your React app works fine in Chrome but crashes on Safari iOS 15. You cannot reproduce it locally. How do you debug this?
When would you choose React over Vue or Angular for a new project? What are the actual tradeoffs, not just marketing?
What is the difference between authentication and authorization? Give examples of getting each wrong.
Explain how React's key prop affects performance and correctness. Give an example where using array index as key causes a bug.
Explain Spring Boot auto-configuration. How does @SpringBootApplication work under the hood? What is the difference between @Component, @Service, @Repository, and @Controller in Spring?
You deploy a React app and users report a blank white screen on IE11. Your CI/CD passes. What's happening and how do you fix it?
Given a string with brackets, check if it's valid. Valid: every open bracket has a matching close bracket in correct order.
Implement merge sort and explain its advantages over quicksort.
Your TypeScript codebase has many 'as any' casts. A new developer says 'it's just to make the code compile.' What's the real cost?
After a React upgrade from v17 to v18, your useEffect fires twice in development even though it wasn't before. Several API calls are duplicated. A junior dev asks you to 'just add a flag'. What's the real explanation and the correct fix?
What is the difference between TypeScript's interface and type alias? When would you use each?
Write a SQL query to find the second highest salary from an Employee table. Show at least two approaches: using LIMIT/OFFSET, using a subquery with MAX, and using DENSE_RANK(). Discuss which is most efficient and why.
Design a library management system with online book reservation. Students can search, reserve, and borrow books. Librarians can manage inventory. Cover the database schema, REST APIs, and how you handle concurrent reservations of the last copy.
Your Docker container works on developer machines but fails in production with 'Permission denied' errors accessing /data volume. All developers use Mac, production runs on Linux. What's the issue?
Given an array of integers, find two numbers that sum to a target. Optimize for O(n) time and O(n) space.
How do you model a tree structure (category hierarchy) in MongoDB? Compare parent-reference, child-reference, and materialized path.
Scrum master asks for your estimate on a task. You have no idea how long it will take. Other team members are giving estimates confidently. What do you say?
What is a MongoDB aggregation pipeline? Write one that joins two collections and computes grouped statistics.
Explain the difference between HashMap and ConcurrentHashMap in Java. When would you use each? Describe segment locking in Java 7 vs the CAS-based approach in Java 8+, and why you should never use HashMap in a multi-threaded context.
Explain when you should NOT use MongoDB and should use a relational database instead.
Your CI/CD pipeline builds a Docker image on every commit. Build time is 18 minutes. 15 minutes is just npm install. How do you reduce this without caching all npm packages globally?
A developer creates an index on every column 'to make queries faster.' Why is this wrong and what's the actual impact?
You're asked to take over a project where the previous engineer left no documentation and the code is a mess. The deadline is in 3 weeks. How do you approach this?
Explain window functions with an example. How is RANK() different from DENSE_RANK() and ROW_NUMBER()?
Tell me about a time you worked in a large team and had to coordinate your work with multiple developers. How did you avoid merge conflicts and integration issues?
Your application uses Redis KEYS * command in production to list all cache keys. The application hangs for several seconds periodically. Why?
Design a REST API for an e-commerce cart system. Define the endpoints (add item, remove item, get cart, checkout), explain authentication with JWT, handle race conditions on inventory, and discuss idempotency for the checkout endpoint.
Write a query to find the second highest salary from an employees table. What if there are multiple employees with the highest salary?
What are Python generators and when would you use them over lists? Implement a Fibonacci generator.
A developer asks: 'Should I use PUT or PATCH for updating a resource?' What's the correct answer?
How do you handle transactions in Spring Boot? Explain the @Transactional annotation, propagation levels (REQUIRED, REQUIRES_NEW, NESTED), isolation levels, and how Spring proxies intercept methods — including why self-invocation bypasses the proxy.
What is the difference between @staticmethod and @classmethod in Python? Give use cases for each.
A Django application using ORM makes 1 query per user in a list view. When the list has 500 users, the page makes 501 queries (1 for user list + 1 per user for their profile). Fix this with minimal code changes.
You're building a feature that requires reading from a database 1000 times per request (for each item in a list). Batching is not possible due to the library you must use. What do you do?
Your Python scraper fails with 'SSL: CERTIFICATE_VERIFY_FAILED'. A colleague suggests verify=False. Why is that dangerous and what's the correct fix?
Explain the difference between deepcopy and shallow copy in Python. Give a scenario where using shallow copy caused a bug.
Your Python service runs in Docker. On developer machines (Mac M1) it works fine. In production (Linux x86) it crashes with a C extension error. What's happening and how do you fix it?
You have a Spring Boot service that reads from a config file. In production, changing the config requires a restart. Implement dynamic config refresh without restart.
You have a Java application with a class hierarchy 10 levels deep using inheritance. New requirements keep breaking existing behavior. A senior architect says 'prefer composition over inheritance'. Refactor this without changing the external API.
Your Flask API crashes with 'RuntimeError: Working outside of application context.' When does this happen?
Explain Java's try-catch-finally execution order. What happens when both catch and finally throw exceptions?
Your application uses @Async in Spring Boot but tasks are dropping silently. No exceptions are logged. The async methods return void. How do you debug and fix this?
Write a Python context manager for a database transaction that commits on success and rolls back on exception.
Your Express app serves API and static files. Under load, static file serving consumes most of CPU. How do you fix this?
Explain the difference between long-polling, WebSocket, and Server-Sent Events (SSE) for real-time features.
Explain Java records (Java 16+). What problems do they solve compared to regular classes?
Your Spring Boot microservice processes 10,000 HTTP requests per minute. You add a feature that makes one additional database call per request. Response time jumps from 50ms to 800ms. Explain the performance model and fix.
Your Java application uses Hibernate. You notice N+1 queries when loading a list of entities with a @OneToMany relationship. Fix this without changing the database schema.
Implement a function to check if two strings are anagrams of each other. Then solve for: given a string and a pattern, find all anagram substrings.
You have a microservice with 50 REST endpoints built with Spring Boot. A new requirement says every request must log user ID, request ID, and duration. You cannot modify 50 controllers. How do you implement this?
How does quicksort choose a pivot and what makes it O(n²) in the worst case?
You're seeing ConcurrentModificationException in production but not in tests. The code iterates over a HashMap inside a method that looks safe. What are the possible causes in a multi-threaded environment?
Your API suddenly starts returning 404 for an endpoint that worked yesterday. No code was deployed. What do you investigate?
Write a function to validate if a given string is a valid IP address (both IPv4 and IPv6).
You have a Java service that processes files. After processing 100 files, you get OutOfMemoryError: GC Overhead Limit Exceeded. Your code closes all streams. What else could cause this?
What is Node.js's unhandledRejection event? How does it behave differently in Node 15+ vs earlier versions?
Explain the time and space complexity of hash table operations. What happens when load factor is too high?
Your Spring Boot application starts fine but after 2 hours of production traffic, all requests start returning HTTP 500 with 'Unable to acquire JDBC Connection'. Memory and CPU look normal. What's happening?
Explain the difference between checked and unchecked exceptions in Java. Why do some frameworks (Spring, Lombok) convert checked to unchecked?
A developer has written res.send(eval(req.body.expression)) in your Express app. What are all the problems?
What is the difference between DFS and BFS? When does each find the optimal solution?
You have a Spring Boot application where @Transactional is not working — changes are not being rolled back on exceptions. You've verified the exception is a RuntimeException. What are the possible causes?
Your Spring Boot application beans form a circular dependency: A depends on B, B depends on A. It fails at startup. How do you resolve this without @Lazy?
You're mid-feature and your tech lead pushes a breaking API change to a shared internal library. Your branch is now broken. Team meeting in 2 hours. What do you do?
How do you prevent clickjacking and what is the X-Frame-Options header?
Explain Java's Optional. A code review shows: Optional.get() called without isPresent() check. What's the problem and what's the idiomatic fix?
Your React Native app gets a 1-star review: 'The app crashes every time I open it.' You cannot reproduce it. Logs show nothing. How do you debug this?
What is the difference between require() and ES module import in Node.js? What problems arise when mixing them?
What is the difference between symmetric and asymmetric encryption? When would you use each in a web application?
Your Spring Boot startup time is 45 seconds with 200 beans. How do you reduce it?
Your Java application creates a new Thread inside a loop that processes 10,000 items. Each thread makes a database call. Why is this a bad design and how do you fix it?
Your microservice calls 5 external services. You want to test it in isolation without calling real services. How do you set up testing?
You call a @Transactional service method from another @Transactional method in the same class. What transaction behavior do you get, and why?
Explain what happens when Spring beans have different scopes: @Singleton depends on @Prototype. What's the problem and how do you fix it?
You're implementing a REST API with Spring Boot. How do you handle validation and return proper error responses without try-catch in every controller?
What is SQL injection and how do you prevent it in a Python Flask app that takes user search input?
Explain the difference between @Component, @Service, @Repository, and @Controller in Spring. Are they interchangeable?
You have a @RestController that takes a large request body (100MB file upload). Server runs out of heap memory when multiple uploads happen simultaneously. Fix this.
Explain how Java's try-with-resources works. What happens if both the try block and close() throw exceptions?
What is Spring's ApplicationContext vs BeanFactory? When would you use BeanFactory?
What is Java's ClassLoader hierarchy and when does it cause ClassCastException across classloaders?
You're using useReducer for complex form state. The reducer is being called twice in development. Is this a bug?
Explain Spring Security's filter chain. What's the order of filters and why does it matter?
Your Spring Boot app is hitting 429 rate limit errors from an external API. Implement a solution.
Explain the difference between RANK(), DENSE_RANK(), and ROW_NUMBER() window functions.
Your Spring Boot app has 20 @Scheduled tasks. In a multi-instance deployment, all 10 instances run every scheduled task simultaneously, causing duplicate processing. How do you fix this?
What are functional interfaces in Java 8? List the four main ones and their use cases.
Your OLTP database is being used for reporting queries that scan millions of rows, causing locks that block transactional queries. You cannot add more hardware immediately. What do you do today?
Explain Spring Boot auto-configuration. How does @ConditionalOnClass work? Write a scenario where it prevents a bean from being created.
Write a Java 8 Stream pipeline: filter employees earning >50K, group by department, compute average salary per department, sorted by average descending.
Your Spring Boot service exposes 50 REST endpoints. How do you implement versioning so old clients using /v1 still work while new clients use /v2?
Your Java app's heap dump shows hundreds of thousands of HashMap$Entry objects. What are the likely causes?
A developer writes SELECT * FROM users WHERE email LIKE '%@gmail.com'. It's slow despite an index on email. Why? How would you make this fast while keeping the same search capability?
You have a React component that renders a chart. The chart library is 500KB. It's only shown in a modal that 10% of users ever open. How do you optimize the initial load?
Explain differences between abstract class and interface in Java 8+. With default methods in interfaces, when would you still choose abstract class?
Your React application shows 'Cannot update a component from inside the function body of a different component.' What causes this?
You're asked to delete 10 million old log records from a 50M row table. A simple DELETE WHERE created_at < '2024-01-01' locks the table for hours. How do you do this safely in production?
Write a SQL query to detect duplicate rows in a table and delete all but one (keeping the one with the lowest ID).
What are React portals and when do you need them?
You need to find duplicate records in a table of 10 million rows based on email, phone, and name (any two matching means duplicate). Write the SQL and explain the performance considerations.
A developer says 'I never need Redux because Context API can do everything Redux does.' Is this true?
You have a MySQL query with GROUP BY that was fast on 1 million rows and is now slow on 50 million. EXPLAIN shows 'Using filesort' and 'Using temporary'. What does this mean and how do you fix it?
What are database transactions and ACID properties? Give a real example where violating each property causes data corruption.
Explain how Spring Boot handles connection pooling with HikariCP. What happens when the pool is exhausted?
Your application has this query pattern: SELECT * FROM orders WHERE status='pending' running every 5 seconds. Table has 50M rows, 99.9% of orders are 'completed'. An index on status exists. EXPLAIN shows it's still doing a table scan. Why?
You're migrating a large JavaScript codebase to TypeScript. You have 500 files. What's your migration strategy to avoid a big-bang rewrite?
Write a SQL query to find the second highest salary from an Employees table without using LIMIT/TOP or subqueries.
What is Spring Batch? How does it handle restartable jobs that fail midway through processing 1 million records?
Given a string, find the length of the longest substring without repeating characters. 'abcabcbb' → 3 ('abc').
You run EXPLAIN ANALYZE on a query joining 4 tables. It shows 'Hash Join' with 'rows=1 actual rows=50000'. What does this tell you and what's your fix?
What happens to React component state when you conditionally render it: {show && <Counter />}. User clicks 3 times. show=false, then show=true. What's the counter value?
What is Spring Security's filter chain? How would you implement JWT authentication in it?
Practice these questions with AI feedback
Get instant grading on your answers, identify your weak areas, and generate a personalised 14-day study plan — all free.
Build my study plan →