Software Engineer interview questions
32 questions written for Software Engineer roles, plus the HR and behavioural questions you'll face everywhere. Each has a model answer and the follow-ups to expect.
68 questions
HRMotivationMediumYou studied mechanical engineering. Why do you want to move into IT?
Reported at TCS, Infosys, Wipro, Cognizant, Accenture, Capgemini
You studied mechanical engineering. Why do you want to move into IT?
Reported at TCS, Infosys, Wipro, Cognizant, Accenture, Capgemini
What they are checking: Whether the switch is a real interest backed by effort, or just a fallback.
Model answer
I enjoyed mechanical engineering, but the part I liked most was writing MATLAB and Python scripts to analyse our lab data. In my third year I automated our thermodynamics lab calculations, which saved my batch hours every week, and I realised I wanted to build software full time.
Since then I've completed [the NPTEL Python and DBMS courses], solved around 150 coding problems, and built a small inventory app for a local hardware shop using Python and SQLite.
My mechanical background also helps: I'm used to working with real-world constraints and data, which is useful in manufacturing and automotive client projects.
Tips
- Show what you have already done to make the switch.
- Turn your core branch into an advantage.
HRSelf-assessmentMediumWhich programming language are you most comfortable with? Rate yourself out of 10.
Reported at TCS, Infosys, Wipro, Cognizant
Which programming language are you most comfortable with? Rate yourself out of 10.
Reported at TCS, Infosys, Wipro, Cognizant
What they are checking: A trap and a guide. Whatever language and number you give decides how hard the next questions are.
Model answer
I'm most comfortable with Java. I'd rate myself a 7 out of 10.
I'm confident with OOP, collections like ArrayList and HashMap, exception handling, and writing programs on arrays and strings. I've built two projects in Java, including a Spring Boot REST API.
I'm not giving myself higher because I haven't worked much with multithreading or the JVM's memory internals in a real project yet. Those are what I'm learning next.
Tips
- Do not say 9 or 10; the interviewer will try to prove you wrong.
- Say what you know and what you do not. That honesty is what they are testing.
Likely follow-ups
- What is the difference between HashMap and Hashtable?
- Write a program to reverse a string in Java.
- What is the difference between == and equals()?
HRFlexibilityEasyYou may be placed in testing or support rather than development. Is that okay?
Reported at Accenture, Capgemini, Cognizant, TCS
You may be placed in testing or support rather than development. Is that okay?
Reported at Accenture, Capgemini, Cognizant, TCS
What they are checking: Flexibility. Freshers are allocated based on project needs, not preference.
Model answer
Yes. Whatever I start with, I'll learn how real systems work in production, how clients use them, and how problems are found and fixed. Testing especially builds the habit of thinking about edge cases, which makes you a better developer later.
I'd do the work well and, over time, show through my performance and certifications that I'm ready for development work as well.
BehaviouralProblem solvingHardWhat is the most technically challenging problem you have solved?
Reported at Google, Microsoft, Amazon
What is the most technically challenging problem you have solved?
Reported at Google, Microsoft, Amazon
What they are checking: Depth. They will keep asking "why" until they reach the limit of what you know, so pick something you understand completely.
Model answer
In my internship, our app's order page sometimes showed duplicate orders, roughly 1 in 500. Nobody could reproduce it locally.
I added logging with request IDs and found that duplicates always came in pairs about 300 ms apart. The mobile app retried a request whenever the network was slow, and our server processed both requests because it had no way to tell they were the same order.
I proposed an idempotency key: the app generates a unique ID per order, and the server stores it with a unique constraint in the database. A second request with the same ID returns the original order instead of creating a new one. I wrote the migration, the server change and tests that simulated the retry.
Duplicate orders went to zero over the following month. The thing I learned is to reproduce with data from production before guessing at a fix.
Likely follow-ups
- Why a database constraint and not a check in code?
- How long do you keep the idempotency keys?
- What happens if two requests arrive at exactly the same moment?
TechnicalOOPEasyExplain the four pillars of object-oriented programming with examples.
Reported at TCS, Infosys, Wipro, Cognizant, Accenture, Capgemini
Explain the four pillars of object-oriented programming with examples.
Reported at TCS, Infosys, Wipro, Cognizant, Accenture, Capgemini
What they are checking: The single most common fresher technical question. They want clear definitions and an everyday example for each, not textbook lines.
Model answer
- Encapsulation: keeping data and the methods that change it together, and hiding the data behind those methods. A BankAccount class keeps balance private and only allows changes through deposit() and withdraw(), which can check for a negative balance.
- Abstraction: showing only what the user needs and hiding how it works. You call car.start() without knowing how the fuel injection works. In Java this is done with abstract classes and interfaces.
- Inheritance: a class reusing and extending another class. SavingsAccount extends BankAccount and adds interest calculation without rewriting deposit and withdraw.
- Polymorphism: one interface, many forms. A Shape reference can hold a Circle or a Square, and shape.area() runs the right version at run time (overriding). Method overloading, the same method name with different parameters, is compile-time polymorphism.
Encapsulation is about protecting data, while abstraction is about hiding complexity; interviewers often ask for that difference next.
Likely follow-ups
- What is the difference between overloading and overriding?
- Can you achieve multiple inheritance in Java?
- Abstraction vs encapsulation?
TechnicalOperating systemsEasyWhat is the difference between a process and a thread?
Reported at TCS, Infosys, Wipro, Capgemini, Microsoft
What is the difference between a process and a thread?
Reported at TCS, Infosys, Wipro, Capgemini, Microsoft
What they are checking: Basic OS understanding, often a lead-in to concurrency questions.
Model answer
A process is a running program with its own memory space. A thread is a unit of execution inside a process; all threads of a process share its memory.
- Memory: processes are isolated from each other; threads share heap memory and global data but each has its own stack.
- Cost: creating and switching between processes is more expensive than threads.
- Communication: processes need inter-process communication (pipes, sockets, shared memory); threads can simply read shared variables, which is fast but needs locks to stay correct.
- Failure: if one process crashes others keep running; a crashing thread can bring down its whole process.
Example: each Chrome tab runs as a separate process so one bad tab doesn't crash the browser, while inside a tab, separate threads handle rendering and JavaScript.
Likely follow-ups
- What is a race condition?
- What is a mutex?
TechnicalOperating systemsMediumWhat is a deadlock? What conditions cause it and how can you prevent it?
Reported at TCS, Infosys, Microsoft, Amazon
What is a deadlock? What conditions cause it and how can you prevent it?
Reported at TCS, Infosys, Microsoft, Amazon
What they are checking: Concurrency fundamentals.
Model answer
A deadlock is when two or more processes wait for each other forever. Thread A holds lock 1 and waits for lock 2, while thread B holds lock 2 and waits for lock 1.
All four conditions must hold at the same time (the Coffman conditions):
- Mutual exclusion: a resource can be held by only one process.
- Hold and wait: a process holds one resource while waiting for another.
- No preemption: resources cannot be taken away forcibly.
- Circular wait: a cycle of processes, each waiting for the next.
Prevention means breaking any one condition. The most practical is to break circular wait by always acquiring locks in a fixed global order. Other options are timeouts on lock acquisition, or acquiring all needed resources at once. Avoidance algorithms like the Banker's algorithm check that granting a request keeps the system in a safe state.
TechnicalDatabasesMediumWhen would you choose a SQL database and when a NoSQL database?
Reported at Amazon, Flipkart, Accenture
When would you choose a SQL database and when a NoSQL database?
Reported at Amazon, Flipkart, Accenture
What they are checking: Whether you understand trade-offs rather than trends.
Model answer
SQL databases (MySQL, PostgreSQL) store data in tables with a fixed schema and relationships, support joins, and give strong ACID guarantees. NoSQL databases (MongoDB, DynamoDB, Cassandra, Redis) use documents, key-value pairs or wide columns, have flexible schemas, and are built to scale horizontally.
Choose SQL when:
- Data is structured and related, such as orders, customers and payments.
- You need transactions that must be correct, such as transferring money.
- You need complex queries and reports with joins.
Choose NoSQL when:
- The schema changes often or varies per record, such as product catalogues with different attributes.
- You need huge scale with simple access patterns, such as a shopping cart or session store looked up by key.
- You need very fast reads of denormalised data.
Many real systems use both: PostgreSQL for orders and payments, Redis for caching, and a document store for the catalogue.
TechnicalDatabasesMediumWhat is normalisation? Explain 1NF, 2NF and 3NF.
Reported at TCS, Infosys, Wipro, Cognizant, Capgemini
What is normalisation? Explain 1NF, 2NF and 3NF.
Reported at TCS, Infosys, Wipro, Cognizant, Capgemini
What they are checking: DBMS fundamentals, very common in service-company interviews.
Model answer
Normalisation is organising tables to reduce duplicate data and avoid update problems.
- 1NF: every column holds a single value, with no lists or repeating groups. A "phones" column holding "98xxx, 99xxx" breaks 1NF; move phones to separate rows or a separate table.
- 2NF: 1NF, plus every non-key column depends on the whole primary key, not part of it. In a table keyed on (student_id, course_id), student_name depends only on student_id, so it belongs in a Students table.
- 3NF: 2NF, plus non-key columns depend only on the key, not on other non-key columns. If a Students table has department_id and department_name, department_name depends on department_id, so move it to a Departments table.
Without normalisation, renaming a department means updating thousands of rows, and missing one leaves the data inconsistent. In analytics systems, we sometimes denormalise on purpose to make reads faster.
Likely follow-ups
- What is BCNF?
- When would you denormalise?
TechnicalDatabasesEasyWhat is the difference between a primary key, a unique key and a foreign key?
Reported at TCS, Infosys, Wipro, Cognizant
What is the difference between a primary key, a unique key and a foreign key?
Reported at TCS, Infosys, Wipro, Cognizant
What they are checking: DBMS basics.
Model answer
- Primary key: uniquely identifies each row. It cannot be NULL and a table has only one, such as student_id.
- Unique key: values must be unique but, in most databases, it can contain NULL, and a table can have several, such as email or phone.
- Foreign key: a column that refers to the primary key of another table, enforcing the relationship. Enrollments.student_id refers to Students.student_id, so you cannot enrol a student who doesn't exist.
By default, a primary key also creates a clustered index in databases such as SQL Server and MySQL's InnoDB, which decides the physical order of rows.
TechnicalDatabasesMediumWhat are ACID properties?
Reported at Infosys, Accenture, Amazon
What are ACID properties?
Reported at Infosys, Accenture, Amazon
What they are checking: Understanding of transactions, often illustrated with a bank transfer.
Model answer
ACID describes what a database guarantees for a transaction. Take transferring ₹500 from A to B:
- Atomicity: all or nothing. Either both the debit from A and the credit to B happen, or neither does.
- Consistency: the transaction moves the database from one valid state to another; rules such as "balance cannot be negative" are never broken.
- Isolation: concurrent transactions don't see each other's half-finished work; two transfers from A at the same time behave as if run one after the other.
- Durability: once committed, the transfer survives a crash or power failure, because it is written to disk or a log.
TechnicalJavaMediumWhat is the difference between an abstract class and an interface in Java?
Reported at TCS, Infosys, Cognizant, Wipro, Capgemini
What is the difference between an abstract class and an interface in Java?
Reported at TCS, Infosys, Cognizant, Wipro, Capgemini
What they are checking: Java OOP depth.
Model answer
- Methods: an abstract class can have abstract and fully implemented methods. An interface has abstract methods, and since Java 8 can also have default and static methods.
- State: an abstract class can have instance variables and constructors. Interface fields are always public static final constants.
- Inheritance: a class can extend only one abstract class but implement many interfaces.
- Access: abstract class members can be private or protected; interface methods are public.
Use an abstract class when related classes share code and state, such as a base Vehicle with a common fuel field. Use an interface to define a capability that unrelated classes can share, such as Comparable or Runnable.
interface Payable { double pay(); }
abstract class Employee implements Payable {
protected String name;
Employee(String name) { this.name = name; }
abstract double monthlySalary();
public double pay() { return monthlySalary(); }
}
class FullTime extends Employee {
FullTime(String name) { super(name); }
double monthlySalary() { return 50000; }
}TechnicalProgramming basicsEasyWhat is the difference between call by value and call by reference?
Reported at TCS, Zoho, Wipro
What is the difference between call by value and call by reference?
Reported at TCS, Zoho, Wipro
What they are checking: Basic understanding of how arguments pass, often asked in C.
Model answer
In call by value, the function receives a copy of the argument, so changes inside the function don't affect the caller's variable. In call by reference, the function receives the address of the variable, so changes do affect the caller.
void byValue(int x) { x = 100; } /* caller's variable unchanged */
void byRef(int *x) { *x = 100; } /* caller's variable becomes 100 */
int main(void) {
int a = 5;
byValue(a); /* a is still 5 */
byRef(&a); /* a is now 100 */
return 0;
}C only has call by value; passing a pointer simulates call by reference. Java is also always pass by value, but for objects the value passed is the reference, so a method can change the object's fields but cannot make the caller's variable point to a different object.
TechnicalWebMediumWhat is a REST API? What do the HTTP methods mean?
Reported at Accenture, Cognizant, Flipkart
What is a REST API? What do the HTTP methods mean?
Reported at Accenture, Cognizant, Flipkart
What they are checking: Web development fundamentals.
Model answer
REST is a style for building web APIs where everything is a resource with a URL, and you act on it with standard HTTP methods. Requests are stateless: each one carries everything the server needs, such as an auth token.
- GET /students/12: read student 12. Safe, no changes.
- POST /students: create a new student.
- PUT /students/12: replace student 12 completely.
- PATCH /students/12: update some fields of student 12.
- DELETE /students/12: delete student 12.
Responses use status codes: 200 OK, 201 Created, 400 Bad Request, 401 Unauthorized, 404 Not Found, 500 Server Error.
GET, PUT and DELETE are idempotent, meaning repeating the same request has the same effect as doing it once. POST is not, which is why retrying a POST can create duplicates.
TechnicalNetworkingHardWhat happens when you type a URL into the browser and press Enter?
Reported at Google, Microsoft, Amazon, Flipkart
What happens when you type a URL into the browser and press Enter?
Reported at Google, Microsoft, Amazon, Flipkart
What they are checking: Breadth across networking, the web and browsers. Go step by step, and go deep where you are strongest.
Model answer
- URL parsing: the browser works out the protocol (https), the domain and the path.
- DNS lookup: it finds the IP address of the domain, checking the browser cache, the OS cache, the router and then the ISP's DNS resolver, which may query root, TLD and authoritative name servers.
- TCP connection: the browser opens a connection to the IP on port 443 with a three-way handshake (SYN, SYN-ACK, ACK).
- TLS handshake: browser and server agree on encryption, the server proves its identity with a certificate, and they set up session keys.
- HTTP request: the browser sends GET /path with headers such as cookies and accepted formats.
- Server side: a load balancer passes the request to an app server, which may check a cache, query a database and build the response.
- HTTP response: status code, headers and the HTML body come back.
- Rendering: the browser parses HTML into the DOM and CSS into the CSSOM, runs JavaScript, then lays out and paints the page. Extra requests are made for images, scripts and stylesheets, often from a CDN.
Interviewers usually stop you at one step and ask for more depth, most often DNS, TLS or rendering.
Likely follow-ups
- How does DNS caching work?
- What is a CDN?
- What changes with HTTP/2?
TechnicalData structuresEasyWhat is the difference between a stack and a queue? Give real uses.
Reported at TCS, Infosys, Wipro, Cognizant, Capgemini
What is the difference between a stack and a queue? Give real uses.
Reported at TCS, Infosys, Wipro, Cognizant, Capgemini
What they are checking: Data structure basics.
Model answer
A stack is Last In, First Out: you push and pop from the same end, like a pile of plates. A queue is First In, First Out: you add at the back and remove from the front, like a ticket line.
Stack uses: undo in an editor, the browser back button, function calls (the call stack), checking balanced brackets, depth-first search.
Queue uses: printer jobs, handling requests in order on a server, breadth-first search, message queues between services.
Both support their main operations in O(1) time.
Likely follow-ups
- How would you implement a queue using two stacks?
TechnicalAlgorithmsEasyExplain binary search and its time complexity.
Reported at TCS, Infosys, Accenture, Cognizant
Explain binary search and its time complexity.
Reported at TCS, Infosys, Accenture, Cognizant
What they are checking: Algorithm basics and the ability to code it without off-by-one errors.
Model answer
Binary search finds an element in a sorted array by repeatedly halving the search range. Compare the target to the middle element: if equal you're done; if smaller search the left half; if larger search the right half.
Each step halves the range, so it takes O(log n) time; one million elements need at most about 20 comparisons. It uses O(1) extra space when written iteratively. It only works on sorted data.
def binary_search(arr, target):
lo, hi = 0, len(arr) - 1
while lo <= hi:
mid = lo + (hi - lo) // 2
if arr[mid] == target:
return mid
if arr[mid] < target:
lo = mid + 1
else:
hi = mid - 1
return -1Writing mid = lo + (hi - lo) // 2 instead of (lo + hi) // 2 avoids integer overflow in languages like Java and C++.
TechnicalToolsMediumWhat is the difference between git merge and git rebase?
Reported at Microsoft, Flipkart
What is the difference between git merge and git rebase?
Reported at Microsoft, Flipkart
What they are checking: Practical engineering experience.
Model answer
Both bring changes from one branch into another.
- git merge creates a new merge commit that joins the two histories. History is preserved exactly as it happened but can look tangled.
- git rebase moves your commits so they sit on top of the latest target branch, rewriting them as new commits. History becomes a clean straight line.
The rule: never rebase commits that others have already pulled, because rewriting shared history causes conflicts for everyone. A common workflow is to rebase your own feature branch on main to stay up to date, then merge it into main through a pull request.
TechnicalCodingEasyWrite a program to reverse a string without using built-in reverse functions.
Reported at TCS, Infosys, Wipro, Cognizant, Capgemini
Write a program to reverse a string without using built-in reverse functions.
Reported at TCS, Infosys, Wipro, Cognizant, Capgemini
What they are checking: Basic coding fluency. Talk through the approach before writing.
Model answer
Use two pointers, one at each end, and swap characters as they move towards the middle. O(n) time and O(n) space (Java strings are immutable, so we work on a char array).
static String reverse(String s) {
char[] c = s.toCharArray();
int i = 0, j = c.length - 1;
while (i < j) {
char t = c[i];
c[i] = c[j];
c[j] = t;
i++;
j--;
}
return new String(c);
}Test cases to mention: an empty string, a single character, and an even and an odd length.
Likely follow-ups
- Reverse the words in a sentence instead of the characters.
- Check whether a string is a palindrome.
TechnicalCodingEasyCheck whether a number is a palindrome.
Reported at TCS, Wipro, Cognizant, Zoho
Check whether a number is a palindrome.
Reported at TCS, Wipro, Cognizant, Zoho
What they are checking: Loops and arithmetic without converting to a string.
Model answer
Reverse the number digit by digit using % 10 and // 10, then compare with the original. Negative numbers are not palindromes.
def is_palindrome(n):
if n < 0:
return False
original, rev = n, 0
while n > 0:
rev = rev * 10 + n % 10
n //= 10
return original == rev
print(is_palindrome(121)) # True
print(is_palindrome(123)) # FalseTime is O(d) where d is the number of digits.
