📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š .NET Interview Questions

377 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.

Phase 1 — Computer Science Fundamentals

How computers, operating systems, file systems and networks really work, plus the core data structures and algorithms, explained for .NET 10 engineers.

  1. A map (dictionary) associates keys with values. Compare the map types in .NET: Dictionary, SortedDictionary, SortedList, OrderedDictionary, ConcurrentDictionary, FrozenDictionary, ImmutableDictionary and ILookup. How do you choose?

    The map abstraction and .NET's map implementations: hash vs tree vs sorted array, ordering, concurrency, frozen and immutable variants, multi-maps, and how to choose by access pattern.

    Mid-Level Theory Data Structures Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  2. What are trees, binary trees and binary search trees? Explain traversals, why balance matters, and where trees appear in real .NET systems and databases.

    Tree terminology, binary trees and BSTs, in/pre/post/level-order traversals, balanced trees (red-black, AVL), B-trees in database indexes, and real-world trees in .NET.

    Mid-Level Theory Data Structures Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  3. What is a heap data structure, and how does PriorityQueue<TElement,TPriority> work in .NET? Show how you would find the top K items from a large stream efficiently.

    Binary and d-ary heaps stored in arrays, heap operations and costs, PriorityQueue in .NET (min-heap, no stability, Remove in .NET 9), and classic uses: top-K, scheduling, merging sorted streams and Dijkstra.

    Mid-Level Coding Data Structures Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  4. What is a graph data structure? How do you represent one in C#, and where do graphs show up in real backend systems (dependencies, workflows, permissions)? How would you detect a cycle or find a valid execution order?

    Graph terminology, adjacency list vs matrix vs edge list, directed acyclic graphs, topological sort and cycle detection, and real-world graphs such as DI containers, build systems and job schedulers.

    Senior Theory Data Structures Β· πŸ”— 4 follow-ups Β· πŸ›  1 real-world
  5. What is a trie (prefix tree)? Implement insert, exact search and prefix search in C#, and discuss when a trie is the right choice for something like autocomplete versus alternatives.

    Trie structure and operations, O(L) insert and search, prefix queries, memory trade-offs and compressed (radix) tries, and alternatives such as sorted arrays, database prefix queries and search engines.

    Mid-Level Coding Data Structures Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  6. Code review: an OrderService keeps orders in a static List<Order>, finds them with FirstOrDefault, dedups with Any before Add, gets recent orders with OrderByDescending().ToList().Take(10), checks a blocklist with new List<string>{...}.Contains, drains a List with RemoveAt(0), and counts with ContainsKey plus the indexer. What is wrong, and how would you rewrite it?

    A collection-focused code review: O(n) lookups and dedup, sorting everything for top-N, per-call allocations, List used as a queue, double dictionary lookups, thread safety and unbounded growth.

    Senior CodeReview Data Structures Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  7. What is Big O notation? Explain O(1), O(log n), O(n), O(n log n), O(n²) and O(2ⁿ) with .NET examples, and the difference between best, average, worst-case and amortised cost.

    Big O notation as a growth-rate language: the common complexity classes, real .NET examples of each, and best/average/worst/amortised analysis.

    Junior Theory Algorithms Β· πŸ”— 3 follow-ups
  8. Code review: what is the time complexity of this .NET code, and how would you make it faster? It loops over orders, calls products.FirstOrDefault(p => p.Id == line.ProductId) per line, builds a report with string +=, and checks seen.Contains(order.Id) on a List<int>.

    Analysing the real time complexity of everyday .NET code with hidden loops, and rewriting it to linear time.

    Mid-Level CodeReview Algorithms Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  9. What is space complexity? How do you analyse the memory an algorithm uses in .NET, including auxiliary space, recursion depth, allocations and the GC, and how do you trade time for space?

    Space complexity in practice: auxiliary versus input space, stack depth from recursion, allocation cost in .NET, and time-space trade-offs.

    Intermediate Theory Algorithms Β· πŸ”— 3 follow-ups
  10. How does binary search work? Implement it in C#, explain its preconditions and edge cases, and compare it with linear search and hash lookup. When would you use each in a .NET application?

    Searching algorithms: linear search, binary search (with a correct implementation and edge cases), hash lookup, and choosing between them in .NET.

    Intermediate Coding Algorithms Β· πŸ”— 3 follow-ups
  11. Which sorting algorithm does .NET use for Array.Sort and List<T>.Sort, and is it stable? Compare quicksort, merge sort, heap sort and insertion sort, and explain when OrderBy, a custom comparer or a non-comparison sort is the better choice.

    Sorting algorithms and their trade-offs, .NET's introsort, stability, OrderBy versus Array.Sort, comparers, and when to use counting or radix sort.

    Mid-Level Theory Algorithms Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  12. What is recursion? Explain base cases, the call stack and stack overflow in .NET, then write a recursive and an iterative version of a tree or folder walk in C#. When should you avoid recursion?

    Recursion fundamentals: base and recursive cases, how the call stack works, StackOverflowException in .NET, and converting recursion to iteration with an explicit stack.

    Junior Coding Algorithms Β· πŸ”— 3 follow-ups
  13. What is dynamic programming? Explain overlapping subproblems and optimal substructure, compare memoisation (top-down) with tabulation (bottom-up), and solve a problem such as minimum coins for an amount in C#.

    Dynamic programming basics: recognising overlapping subproblems and optimal substructure, memoisation versus tabulation, and a worked minimum-coins example with space optimisation.

    Mid-Level Coding Algorithms Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  14. What is a greedy algorithm? Give examples where greedy is optimal (interval scheduling, Dijkstra, Huffman) and where it fails (coin change with arbitrary coins, 0/1 knapsack). How do you decide whether greedy is safe in a real system?

    Greedy algorithms: the greedy-choice property, classic optimal cases, counterexamples, and using greedy heuristics in production scheduling and allocation.

    Mid-Level Theory Algorithms Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  15. What is graph traversal? Explain breadth-first search (BFS) with a C# implementation, why it finds the shortest path in an unweighted graph, and where you would use it in a real system.

    Graph traversal fundamentals and BFS: queue-based implementation, visited sets, shortest paths in unweighted graphs, levels, and real uses like degrees of separation and dependency impact.

    Intermediate Coding Algorithms Β· πŸ”— 3 follow-ups
  16. Explain depth-first search (DFS). Implement it recursively and iteratively in C#, and show how DFS detects cycles in a directed graph and produces a topological order, for example for build or migration dependencies.

    Depth-first search: recursive and iterative implementations, pre/post order, three-colour cycle detection, topological sort, connected components and backtracking.

    Mid-Level Coding Algorithms Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  17. A .NET API endpoint was fast in testing but gets slower every month as production data grows, and now times out for your biggest customers. How would you find and fix an algorithmic complexity problem, and stop it happening again?

    End-to-end handling of a production complexity problem: spotting non-linear growth in metrics, profiling, identifying hidden O(n²) or N+1 patterns, fixing them, and preventing regressions.

    Senior RealWorldScenario Algorithms Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me