Interview Q&A

Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.

4608 total questions 4508 technical 100 career & HR 4272 from PDF library

Showing 1376–1400 of 4608

Career & HR topics

By tech stack

Popular tracks

Junior PDF
What is the Singleton pattern and why is it used?

Short answer: The Singleton pattern ensures a class has only one instance and provides a global point of access to it. It’s commonly used when exactly one object is needed to coordinate actions across the system, such as…

SOLID Read answer
Mid PDF
How do you implement a thread-safe Singleton in .NET?

Short answer: One common thread-safe implementation uses lazy initialization with Lazy<T>: public sealed class Singleton Example code { private static readonly Lazy<Singleton> instance = new Lazy<Singleton…

SOLID Read answer
Mid PDF
What are the common pitfalls of the Singleton pattern?

Short answer: Global state: Singleton can lead to hidden dependencies and make testing difficult. Tight coupling: Other classes depend on the Singleton instance, reducing flexibility. Concurrency issues: If not implement…

SOLID Read answer
Mid PDF
How does the Singleton pattern affect unit testing?

Short answer: Singletons can hinder unit testing because they introduce global state, making tests dependent on a shared instance. This can cause tests to be flaky or order-dependent. To mitigate this, use interfaces and…

SOLID Read answer
Mid PDF
Can you explain the difference between lazy and eager initialization in Singleton?

Short answer: Eager Initialization: The Singleton instance is created at the time of class loading. It's simple but can waste resources if the instance is never used. Lazy Initialization: The instance is created only whe…

SOLID Read answer
Junior PDF
What is the Factory pattern and when would you use it?

Short answer: The Factory pattern is a creational design pattern that provides an interface for creating objects but allows subclasses or implementations to decide which class to instantiate. Explain a bit more It’s used…

SOLID Read answer
Mid PDF
Explain the difference between Factory Method and Abstract Factory patterns.

Short answer: Factory Method: Defines an interface for creating an object but lets subclasses decide which class to instantiate. It uses inheritance and relies on subclass overriding. Abstract Factory: Provides an interf…

SOLID Read answer
Mid PDF
How do you implement a Factory pattern in C#?

Short answer: A simple example of Factory Method: // Product interface public interface IAnimal Example code { void Speak(); } // Concrete Products public class Dog : IAnimal { public void Speak() => Console.WriteLine…

SOLID Read answer
Mid PDF
What are the advantages of using the Factory pattern?

Short answer: Encapsulates object creation: Decouples client code from concrete classes. Promotes code reuse: Centralizes object creation logic. Enhances maintainability: Adding new types requires minimal changes to exis…

SOLID Read answer
Mid PDF
Can Factory pattern help with Dependency Injection?

Short answer: Provide example. Yes! Factory pattern can complement Dependency Injection (DI) by abstracting complex object creation logic, especially when the creation involves runtime parameters or complex setup that DI…

SOLID Read answer
Mid PDF
Can Factory pattern help with Dependency Injection? Provide example.

Short answer: Yes! Factory pattern can complement Dependency Injection (DI) by abstracting complex object creation logic, especially when the creation involves runtime parameters or complex setup that DI containers can’t…

SOLID Read answer
Junior PDF
What is the Strategy pattern and what problem does it solve?

Short answer: The Strategy pattern is a behavioral design pattern that defines a family of algorithms, encapsulates each one, and makes them interchangeable at runtime. It allows the algorithm to vary independently from…

SOLID Read answer
Mid PDF
How would you implement Strategy pattern in .NET?

Short answer: Example: Payment strategy selection // Strategy Interface public interface IPaymentStrategy Example code { void Pay(decimal amount); } // Concrete Strategies public class CreditCardPayment : IPaymentStrateg…

SOLID Read answer
Mid Detailed
Explain Implement Trie (Prefix Tree).

Short answer: Each node has children map/array[26] and an isEnd flag. insert/search/startsWith walk character by character. Tries shine for autocomplete and dictionary prefix queries. Complexity Time O(L) per operation (…

Tries Read answer
Mid Detailed
What coding patterns should you master for FAANG-style interviews?

Short answer: Prioritize: Arrays/Hashing, Two Pointers, Sliding Window, Binary Search, Stack, Linked List, Trees (BFS/DFS), Graphs (BFS/DFS/topo), Heaps, Intervals, 1-D DP, Backtracking, and LRU-style design. Pattern rec…

Interview Strategy Read answer
Junior Detailed
How should you communicate during a live coding interview?

Short answer: Clarify inputs/outputs/constraints first. Propose brute force, then optimize. Speak while coding, test with an example, and state complexity. Silence is riskier than imperfect code with clear thinking. Inte…

Interview Strategy Read answer
Senior
How do you solve Sliding Window Maximum?

Short answer: Monotonic deque storing indices in decreasing height order. As the window slides, pop out-of-window indices from front and smaller values from back. Front is always the max. O(n). Complexity Time O(n), Spac…

Deque / Sliding Window Read answer
Senior
How do you approach Word Ladder (shortest transformation)?

Short answer: Model words as graph nodes; edges connect words differing by one letter. BFS from beginWord finds shortest transformation length. Bidirectional BFS is a strong optimization follow-up. Complexity Time roughl…

Graphs / BFS Read answer
Mid
Explain Rotate Image (matrix) in-place.

Short answer: Transpose the matrix, then reverse each row (for 90° clockwise). Alternatively rotate layer-by-layer swapping four cells. Both are O(n²) time and O(1) extra space. Transpose + reverse is easier to get right…

Matrices Read answer
Mid
How do you find the diameter of a binary tree?

Short answer: Diameter is the longest path between any two nodes (edges count). DFS returns height; at each node update global max of leftHeight + rightHeight. O(n). Path may not pass through the root — that is the commo…

Trees Read answer
Mid
Explain Min Stack design.

Short answer: Keep a normal stack plus an auxiliary stack of current minima (or store pairs). push/pop/top/getMin all O(1). On push, push min(x, currentMin) onto the min stack. Complexity All operations O(1), Space O(n).…

Stacks / Design Read answer
Mid
How do you solve Subsets / Permutations with backtracking?

Short answer: Subsets: at each index choose include/exclude (or loop-based cascading). Permutations: swap/choose unused elements recursively. Always discuss time complexity exponential in n and when to prune. Complexity…

Backtracking Read answer
Junior
What is the difference between BFS and DFS in interviews?

Short answer: BFS uses a queue and finds shortest paths in unweighted graphs / level order. DFS uses a stack/recursion and is natural for path existence, cycle detection, topological sort, and flood fill. Pick based on w…

Graphs Read answer
Mid
How do you detect a cycle in an undirected graph?

Short answer: DFS while tracking parent: visiting an already-visited neighbor that is not the parent means a cycle. Union-Find (Disjoint Set) also works for edge lists: union fails if both ends share a parent. Complexity…

Graphs Read answer
Senior
Explain Longest Common Subsequence (LCS) for interviews.

Short answer: 2-D DP: if s[i]==t[j], dp[i][j] = dp[i-1][j-1]+1 else max(skip either char). Classic O(m*n) table; can compress to two rows for space. Common follow-ups Print the LCS string Longest Common Substring (differ…

Dynamic Programming Read answer

Design Patterns & SOLID Design Patterns in C# · SOLID

Short answer: The Singleton pattern ensures a class has only one instance and provides a global point of access to it. It’s commonly used when exactly one object is needed to coordinate actions across the system, such as configuration settings, logging, or caching.

Real-world example (ShopNest)

ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Short answer: One common thread-safe implementation uses lazy initialization with Lazy<T>: public sealed class Singleton

Example code

{
private static readonly Lazy<Singleton> instance = new
Lazy<Singleton>(() => new Singleton());
private Singleton() { }
public static Singleton Instance => instance.Value;
} This approach ensures thread safety and lazy initialization without locks.

Real-world example (ShopNest)

ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Short answer: Global state: Singleton can lead to hidden dependencies and make testing difficult. Tight coupling: Other classes depend on the Singleton instance, reducing flexibility. Concurrency issues: If not implemented thread-safe, it can cause race conditions. Resource contention: Singleton might become a bottleneck if overused in concurrent environments.

Real-world example (ShopNest)

ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Short answer: Singletons can hinder unit testing because they introduce global state, making tests dependent on a shared instance. This can cause tests to be flaky or order-dependent. To mitigate this, use interfaces and dependency injection, or design the Singleton to allow resetting its state for tests.

Real-world example (ShopNest)

ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Short answer: Eager Initialization: The Singleton instance is created at the time of class loading. It's simple but can waste resources if the instance is never used. Lazy Initialization: The instance is created only when it is first accessed. It saves resources but requires careful implementation for thread safety. Factory pattern Q&A

Real-world example (ShopNest)

ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Short answer: The Factory pattern is a creational design pattern that provides an interface for creating objects but allows subclasses or implementations to decide which class to instantiate.

Explain a bit more

It’s used to encapsulate object creation, promoting loose coupling and flexibility when the exact types of objects aren’t known until runtime. Use case: When a class can’t anticipate the class of objects it needs to create, or when you want to delegate responsibility for object creation to subclasses.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Short answer: Factory Method: Defines an interface for creating an object but lets subclasses decide which class to instantiate. It uses inheritance and relies on subclass overriding. Abstract Factory: Provides an interface to create families of related or dependent objects without specifying their concrete classes. It uses composition and is useful when you need to create multiple related objects together.

Real-world example (ShopNest)

ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Short answer: A simple example of Factory Method: // Product interface public interface IAnimal

Example code

{ void Speak(); } // Concrete Products public class Dog : IAnimal
{
public void Speak() => Console.WriteLine("Woof");
}
public class Cat : IAnimal
{
public void Speak() => Console.WriteLine("Meow");
} // Factory public class AnimalFactory
{
public static IAnimal CreateAnimal(string animalType)
{
return animalType.ToLower() switch
{ "dog" => new Dog(), "cat" => new Cat(), _ => throw new ArgumentException("Invalid animal type") }; }
} Usage: var dog = AnimalFactory.CreateAnimal("dog"); dog.Speak(); // Outputs: Woof

Real-world example (ShopNest)

ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Short answer: Encapsulates object creation: Decouples client code from concrete classes. Promotes code reuse: Centralizes object creation logic. Enhances maintainability: Adding new types requires minimal changes to existing code. Supports polymorphism: Clients work with interfaces or base classes rather than concrete types. Improves testability: Can easily mock or swap factory implementations.

Real-world example (ShopNest)

ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Short answer: Provide example. Yes! Factory pattern can complement Dependency Injection (DI) by abstracting complex object creation logic, especially when the creation involves runtime parameters or complex setup that DI containers can’t handle easily. Example: Imagine a service that needs different data repositories based on a runtime parameter. public interface IRepository { void Save(); }

Example code

public class SqlRepository : IRepository { public void Save() => Console.WriteLine("Saving to SQL DB"); } public class InMemoryRepository : IRepository { public void Save()
=> Console.WriteLine("Saving in Memory"); }
public interface IRepositoryFactory
{ IRepository CreateRepository(string repoType); }
public class RepositoryFactory : IRepositoryFactory
{
public IRepository CreateRepository(string repoType)
{
return repoType.ToLower() switch
{ "sql" => new SqlRepository(), "memory" => new InMemoryRepository(), _ => throw new ArgumentException("Invalid repository type") }; }
} // Consumer class with DI public class Service
{
private readonly IRepositoryFactory _repositoryFactory;
public Service(IRepositoryFactory repositoryFactory)
{
_repositoryFactory = repositoryFactory;
}
public void SaveData(string repoType)
{
var repo = _repositoryFactory.CreateRepository(repoType); repo.Save(); }
} Here, DI injects the IRepositoryFactory while the factory manages object creation based on runtime input. This promotes loose coupling and flexibility. Strategy Design Pattern

Real-world example (ShopNest)

ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Short answer: Yes! Factory pattern can complement Dependency Injection (DI) by abstracting complex object creation logic, especially when the creation involves runtime parameters or complex setup that DI containers can’t handle easily. Example: Imagine a service that needs different data repositories based on a runtime parameter. public interface… IRepository { void……… Save(); } public class SqlRepository : IRepository { public…

Explain a bit more

void Save() => Console.WriteLine("Saving to SQL DB"); } public class InMemoryRepository : IRepository { public void Save() => Console.WriteLine("Saving in Memory"); } public interface IRepositoryFactory { IRepository CreateRepository(string repoType); } public class RepositoryFactory : IRepositoryFactory { public IRepository CreateRepository(string repoType) { return repoType.ToLower() switch { "sql" => new SqlRepository(), "memory" => new InMemoryRepository(), _ => throw new ArgumentException("Invalid repository type") }; } } // Consumer class with DI public class Service { private readonly… Yes! public class SqlRepository : IRepository { public void Save() => Console.WriteLine("Saving to SQL DB"); } public class InMemoryRepository : IRepository { public void Save()

Example code

=> Console.WriteLine("Saving in Memory"); }
public interface IRepositoryFactory
{ IRepository CreateRepository(string repoType); }
public class RepositoryFactory : IRepositoryFactory
{
public IRepository CreateRepository(string repoType)
{
return repoType.ToLower() switch
{ "sql" => new SqlRepository(), "memory" => new InMemoryRepository(), _ => throw new ArgumentException("Invalid repository type") }; }
} // Consumer class with DI public class Service
{
private readonly IRepositoryFactory _repositoryFactory;
public Service(IRepositoryFactory repositoryFactory)
{
_repositoryFactory = repositoryFactory;
}
public void SaveData(string repoType)
{
var repo = _repositoryFactory.CreateRepository(repoType); repo.Save(); }
} Here, DI injects the IRepositoryFactory while the factory manages object creation based on runtime input. This promotes loose coupling and flexibility. Strategy Design Pattern

Real-world example (ShopNest)

ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Short answer: The Strategy pattern is a behavioral design pattern that defines a family of algorithms, encapsulates each one, and makes them interchangeable at runtime. It allows the algorithm to vary independently from clients that use it. Problem it solves: Avoids large if-else or switch statements when selecting behavior and promotes flexibility by decoupling the algorithm from the client using it.

Real-world example (ShopNest)

ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Short answer: Example: Payment strategy selection // Strategy Interface public interface IPaymentStrategy

Example code

{ void Pay(decimal amount); } // Concrete Strategies public class CreditCardPayment : IPaymentStrategy
{
public void Pay(decimal amount) => Console.WriteLine($"Paid {amount} using Credit Card"); }
public class PayPalPayment : IPaymentStrategy
{
public void Pay(decimal amount) => Console.WriteLine($"Paid {amount} using PayPal"); } // Context public class PaymentContext
{
private IPaymentStrategy _paymentStrategy;
public PaymentContext(IPaymentStrategy paymentStrategy)
{
_paymentStrategy = paymentStrategy;
}
public void ExecutePayment(decimal amount)
{ _paymentStrategy.Pay(amount); }
} Usage: var context = new PaymentContext(new PayPalPayment()); context.ExecutePayment(200); // Outputs: Paid 200 using PayPal

Real-world example (ShopNest)

ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

DSA & Coding Interviews Coding Interview FAQ · Tries

Short answer: Each node has children map/array[26] and an isEnd flag. insert/search/startsWith walk character by character. Tries shine for autocomplete and dictionary prefix queries.

Complexity

Time O(L) per operation (L = word length), Space O(total characters).

Common follow-ups

  • Word Search II (Trie + backtracking)
  • Replace Words
Ask if alphabet is lowercase English — array[26] is cleaner than Dictionary.
Permalink & share

DSA & Coding Interviews Coding Interview FAQ · Interview Strategy

Short answer: Prioritize: Arrays/Hashing, Two Pointers, Sliding Window, Binary Search, Stack, Linked List, Trees (BFS/DFS), Graphs (BFS/DFS/topo), Heaps, Intervals, 1-D DP, Backtracking, and LRU-style design. Pattern recognition beats memorizing hundreds of problems.

Interview approach

  1. Finish Blind 75 or NeetCode 150-style coverage once.
  2. Timed practice: aim to solve mediums in ~25 minutes with explanation.
  3. Always narrate brute force → optimize → complexity → edge cases.
  4. Revisit company-tagged mediums from the last 6–12 months.
Depth on patterns beats shallow volume. Quality reps with explanation win offers.
Permalink & share

DSA & Coding Interviews Coding Interview FAQ · Interview Strategy

Short answer: Clarify inputs/outputs/constraints first. Propose brute force, then optimize. Speak while coding, test with an example, and state complexity. Silence is riskier than imperfect code with clear thinking.

Interview approach

  1. Restate the problem in one sentence.
  2. Ask about constraints, duplicates, nulls, and expected complexity.
  3. Outline approaches and pick one with justification.
  4. Code incrementally; verify with a dry run.
  5. Discuss trade-offs and follow-ups even if time ends.

Mistakes to avoid

  • Jumping into code silently
  • Ignoring edge cases
  • Optimizing prematurely without a correct baseline
Interviewers hire teammates — communication is part of the score.
Permalink & share

DSA & Coding Interviews Coding Interview FAQ · Deque / Sliding Window

Short answer: Monotonic deque storing indices in decreasing height order. As the window slides, pop out-of-window indices from front and smaller values from back. Front is always the max. O(n).

Complexity

Time O(n), Space O(k).

This is a classic “monotonic queue” question — name the pattern.
Permalink & share

DSA & Coding Interviews Coding Interview FAQ · Graphs / BFS

Short answer: Model words as graph nodes; edges connect words differing by one letter. BFS from beginWord finds shortest transformation length. Bidirectional BFS is a strong optimization follow-up.

Complexity

Time roughly O(N * L * 26) with wildcards or neighbor generation.

BFS = shortest path in unweighted graph — say that sentence.
Permalink & share

DSA & Coding Interviews Coding Interview FAQ · Matrices

Short answer: Transpose the matrix, then reverse each row (for 90° clockwise). Alternatively rotate layer-by-layer swapping four cells. Both are O(n²) time and O(1) extra space.

Transpose + reverse is easier to get right under pressure.
Permalink & share

DSA & Coding Interviews Coding Interview FAQ · Trees

Short answer: Diameter is the longest path between any two nodes (edges count). DFS returns height; at each node update global max of leftHeight + rightHeight. O(n).

Path may not pass through the root — that is the common trap.
Permalink & share

DSA & Coding Interviews Coding Interview FAQ · Stacks / Design

Short answer: Keep a normal stack plus an auxiliary stack of current minima (or store pairs). push/pop/top/getMin all O(1). On push, push min(x, currentMin) onto the min stack.

Complexity

All operations O(1), Space O(n).

Do not scan the stack for getMin — that is O(n) and fails the prompt.
Permalink & share

DSA & Coding Interviews Coding Interview FAQ · Backtracking

Short answer: Subsets: at each index choose include/exclude (or loop-based cascading). Permutations: swap/choose unused elements recursively. Always discuss time complexity exponential in n and when to prune.

Complexity

Subsets O(n * 2^n); Permutations O(n * n!).

Draw the decision tree for n=3 — it proves you understand recursion depth.
Permalink & share

DSA & Coding Interviews Coding Interview FAQ · Graphs

Short answer: BFS uses a queue and finds shortest paths in unweighted graphs / level order. DFS uses a stack/recursion and is natural for path existence, cycle detection, topological sort, and flood fill. Pick based on what “best” means.

If the question says “shortest” on an unweighted graph, default to BFS.
Permalink & share

DSA & Coding Interviews Coding Interview FAQ · Graphs

Short answer: DFS while tracking parent: visiting an already-visited neighbor that is not the parent means a cycle. Union-Find (Disjoint Set) also works for edge lists: union fails if both ends share a parent.

Complexity

Time O(V + E).

Do not reuse the directed-graph “gray node” story without adjusting for parent.
Permalink & share

DSA & Coding Interviews Coding Interview FAQ · Dynamic Programming

Short answer: 2-D DP: if s[i]==t[j], dp[i][j] = dp[i-1][j-1]+1 else max(skip either char). Classic O(m*n) table; can compress to two rows for space.

Common follow-ups

  • Print the LCS string
  • Longest Common Substring (different recurrence)
  • Edit Distance
Contrast subsequence (not contiguous) vs substring (contiguous) immediately.
Permalink & share
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details