Interview Q&A

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

4616 total questions 4516 technical 100 career & HR 4346 from PDF library

Showing 1–25 of 140

Popular tracks

Mid PDF
Remove duplicate elements from an array (without?

LINQ Distinct()) Logic Use a HashSet to track seen elements. Add elements only if they are not already present. int[] arr = { 1, 2, 3, 2, 4, 1 }; HashSet<int> set = new HashSet<int>(); List<int> result…

Coding Scenarios Read answer
Mid PDF
Find the nth Fibonacci Number int Fibonacci(int n) { if (n <= 1) return n; int a = 0, b = 1; for (int i = 2; i <= n; i++) { int temp = a + b;

Answer: = b; b = temp; } return b; } Explanation: Iterative DP approach; each Fibonacci number is sum of two previous. Follow on: What interviewers expect A clear definition tied to Coding in C# Coding Interview projects…

Coding Read answer
Mid PDF
Find the single non-repeated element in an array where every other?

element appears twice public int SingleNonRepeated(int[] nums) { int result = 0; foreach (int num in nums) { result ^= num; } return result; } Explanation: XOR of a number with itself is 0; XOR with 0 is the number. So d…

Coding Read answer
Mid PDF
Find all anagrams of a string in another string?

public List&lt;int&gt; FindAnagrams(string s, string p) { List&lt;int&gt; result = new List&lt;int&gt;(); if (p.Length &gt; s.Length) return result; int[] pCount = new int[26]; int[] sCount = new int[26]; Follow on: for…

Coding Read answer
Mid PDF
Find all prime factors of a number?

public List&lt;int&gt; PrimeFactors(int n) { List&lt;int&gt; factors = new List&lt;int&gt;(); // Print the number of 2s that divide n while (n % 2 == 0) { factors.Add(2); n /= 2; } // n must be odd at this point for (int…

Coding Read answer
Mid PDF
Find the kth largest element in an unsorted array using Quickselect?

public int FindKthLargest(int[] nums, int k) { return QuickSelect(nums, 0, nums.Length - 1, nums.Length - k); } private int QuickSelect(int[] nums, int left, int right, int kSmallest) { if (left == right) return nums[lef…

Coding Read answer
Mid PDF
Unique Paths in a Grid?

int UniquePaths(int m, int n) { int[,] dp = new int[m, n]; for (int i = 0; i &lt; m; i++) dp[i, 0] = 1; for (int j = 0; j &lt; n; j++) dp[0, j] = 1; for (int i = 1; i &lt; m; i++) { for (int j = 1; j &lt; n; j++) { dp[i,…

Coding Read answer
Mid PDF
BFS on a graph (adjacency list)?

void BFS(Dictionary&lt;int, List&lt;int&gt;&gt; graph, int start) { var visited = new HashSet&lt;int&gt;(); var queue = new Queue&lt;int&gt;(); queue.Enqueue(start); visited.Add(start); while (queue.Count &gt; 0) { int n…

Coding Read answer
Mid PDF
Convert a binary tree to a doubly linked list (in-order)?

public class TreeNode { public int val; public TreeNode left, right; public TreeNode(int x) { val = x; } } TreeNode prev = null; TreeNode head = null; TreeNode ConvertToDLL(TreeNode root) { if (root == null) return null;…

Coding Read answer
Mid PDF
Implement a queue using stacks (efficient enqueue and dequeue)?

public class MyQueue { private Stack&lt;int&gt; stackIn = new Stack&lt;int&gt;(); private Stack&lt;int&gt; stackOut = new Stack&lt;int&gt;(); // Enqueue: push into stackIn (O(1)) public void Enqueue(int x) { stackIn.Push…

Coding Read answer
Mid PDF
Detect a cycle in a linked list and return the node where the cycle?

begins public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; next = null; } } ListNode DetectCycle(ListNode head) { if (head == null) return null; ListNode slow = head, fast = he…

Coding Read answer
Mid PDF
Implement strStr() — Find first occurrence of a?

substring (needle) in a string (haystack) int StrStr(string haystack, string needle) { if (needle == "") return 0; int n = haystack.Length, m = needle.Length; for (int i = 0; i &lt;= n - m; i++) { int j; Follow on: for (…

Coding Read answer
Mid PDF
Count Inversions in an Array?

int MergeSortAndCount(int[] arr, int[] temp, int left, int right) int invCount = 0; if (right &gt; left) int mid = (right + left) / 2; invCount += MergeSortAndCount(arr, temp, left, mid); invCount += MergeSortAndCount(ar…

Coding Read answer
Mid PDF
Greatest Common Divisor (GCD) — Euclidean?

Answer: lgorithm int GCD(int a, int b) { Follow on: while (b != 0) { int temp = b; b = a % b; = temp; } return a; } Explanation: Repeatedly replace (a, b) with (b, a mod b) until b is 0; then a is the GCD. What interview…

Coding Read answer
Mid PDF
Quicksort?

void QuickSort(int[] arr, int low, int high) { if (low &lt; high) Follow on: { int pi = Partition(arr, low, high); QuickSort(arr, low, pi - 1); QuickSort(arr, pi + 1, high); } } int Partition(int[] arr, int low, int high…

Coding Read answer
Mid PDF
Find the nth Fibonacci Number?

Answer: int Fibonacci(int n) if (n &amp;lt;= 1) return n; int a = 0, b = 1; for (int i = 2; i &amp;lt;= n; i++) int temp = a + b; a = b; b = temp; return b; Explanation: Iterative DP approach; each Fibonacci number is su…

Coding Read answer
Mid PDF
Count the number of set bits (1s) in binary representation of an integer public int CountSetBits(int n) { int count = 0; while (n != 0) { count += n & 1; n >>= 1; } return count; } Explanation: Shift through each bit; add 1 to count if least significant bit is set.

Answer: lternative using Brian Kernighan’s algorithm: public int CountSetBits(int n) { int count = 0; while (n != 0) { n &amp;amp;= (n - 1); // Drops the lowest set bit count++; } return count; } Follow on: What intervie…

Coding Read answer
Mid PDF
Mergesort void MergeSort(int[] arr, int left, int right) { if (left < right) { int mid = (left + right) / 2; MergeSort(arr, left, mid); MergeSort(arr, mid + 1, right); Follow on: Merge(arr, left, mid, right); } } void Merge(int[] arr, int left, int mid, int right) { int n1 = mid - left + 1; int n2 = right - mid; int[] L = new int[n1]; int[] R = new int[n2];

rray.Copy(arr, left, L, 0, n1); rray.Copy(arr, mid + 1, R, 0, n2); int i = 0, j = 0, k = left; while (i &lt; n1 &amp;&amp; j &lt; n2) rr[k++] = (L[i] &lt;= R[j]) ? L[i++] : R[j++]; while (i &lt; n1) arr[k++] = L[i++]; wh…

Coding Read answer
Mid PDF
Count the number of 1s in the binary representation of a number?

public int CountOnes(int n) { int count = 0; while (n != 0) { n &amp;= (n - 1); // Drops the lowest set bit count++; } return count; } Explanation: Brian Kernighan’s algorithm efficiently removes the lowest set bit each…

Coding Read answer
Mid PDF
Find the longest common prefix among a list of strings?

public string LongestCommonPrefix(string[] strs) { if (strs == null || strs.Length == 0) return ""; for (int i = 0; i &lt; strs[0].Length; i++) { char c = strs[0][i]; for (int j = 1; j &lt; strs.Length; j++) { if (i == s…

Coding Read answer
Mid PDF
Count the number of set bits (1s) in binary representation of an?

integer public int CountSetBits(int n) { int count = 0; while (n != 0) { count += n &amp; 1; n &gt;&gt;= 1; return count; Explanation: Shift through each bit; add 1 to count if least significant bit is set. Alternative u…

Coding Read answer
Mid PDF
Sort a nearly sorted array (each element at most k positions away)?

public int[] SortNearlySorted(int[] nums, int k) { var result = new List&lt;int&gt;(); var minHeap = new SortedSet&lt;(int val, int index)&gt;(); for (int i = 0; i &lt; nums.Length; i++) { minHeap.Add((nums[i], i)); if (…

Coding Read answer
Mid PDF
Climbing Stairs (1 or 2 steps)?

Answer: int ClimbStairs(int n) { if (n &amp;lt;= 2) return n; int a = 1, b = 2; for (int i = 3; i &amp;lt;= n; i++) { int c = a + b; a = b; b = c; return b; What interviewers expect A clear definition tied to Coding in C…

Coding Read answer
Mid PDF
Number of connected components in undirected graph?

int CountConnectedComponents(Dictionary&lt;int, List&lt;int&gt;&gt; graph) { var visited = new HashSet&lt;int&gt;(); int count = 0; Follow on: foreach (var node in graph.Keys) { if (!visited.Contains(node)) { DFS(node, g…

Coding Read answer
Mid PDF
Find the vertical sum of a binary tree?

void VerticalSum(TreeNode root, int hd, Dictionary&lt;int, int&gt; map) { if (root == null) return; VerticalSum(root.left, hd - 1, map); if (map.ContainsKey(hd)) map[hd] += root.val; else map[hd] = root.val; VerticalSum(…

Coding Read answer

C# Coding Interview C# Programming Tutorial · Coding Scenarios

LINQ Distinct())

Logic

  • Use a HashSet to track seen elements.
  • Add elements only if they are not already present.
int[] arr = { 1, 2, 3, 2, 4, 1 };
HashSet<int> set = new HashSet<int>();
List<int> result = new List<int>();
foreach (int num in arr)
{
if (!set.Contains(num))
{

set.Add(num);

result.Add(num);

}
}

Why this works:

HashSet ensures uniqueness with O(1) lookup.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

Answer: = b; b = temp; } return b; } Explanation: Iterative DP approach; each Fibonacci number is sum of two previous. Follow on:

What interviewers expect

  • A clear definition tied to Coding in C# Coding Interview projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production C# Coding Interview application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in C# Coding Interview architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

element appears twice

public int SingleNonRepeated(int[] nums) {
int result = 0;
foreach (int num in nums) {
result ^= num;
}
return result;
}

Explanation:

XOR of a number with itself is 0; XOR with 0 is the number. So duplicates cancel out,

leaving the unique number.

Follow on:

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

public List<int> FindAnagrams(string s, string p) {
List<int> result = new List<int>();
if (p.Length > s.Length) return result;
int[] pCount = new int[26];
int[] sCount = new int[26];

Follow on:

for (int i = 0; i < p.Length; i++) {

pCount[p[i] - 'a']++;

sCount[s[i] - 'a']++;

}
if (Enumerable.SequenceEqual(pCount, sCount))

result.Add(0);

for (int i = p.Length; i < s.Length; i++) {

sCount[s[i] - 'a']++;

sCount[s[i - p.Length] - 'a']--;

if (Enumerable.SequenceEqual(pCount, sCount))

result.Add(i - p.Length + 1);

}
return result;
}

Explanation:

Sliding window with frequency count arrays for the pattern and current window.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

public List<int> PrimeFactors(int n) {
List<int> factors = new List<int>();

// Print the number of 2s that divide n

while (n % 2 == 0) {

factors.Add(2);

n /= 2;
}

// n must be odd at this point

for (int i = 3; i * i <= n; i += 2) {

while (n % i == 0) {

factors.Add(i);

n /= i;
}
}

Follow on:

// If n is a prime number > 2

if (n > 2) {

factors.Add(n);

}
return factors;
}

Explanation:

We repeatedly divide by 2, then check odd factors up to √n. If leftover n > 2, it's prime.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

public int FindKthLargest(int[] nums, int k) {
return QuickSelect(nums, 0, nums.Length - 1, nums.Length - k);
}
private int QuickSelect(int[] nums, int left, int right, int

kSmallest) {

if (left == right) return nums[left];
int pivotIndex = Partition(nums, left, right);
if (kSmallest == pivotIndex)
return nums[kSmallest];

else if (kSmallest < pivotIndex)

return QuickSelect(nums, left, pivotIndex - 1, kSmallest);

else

return QuickSelect(nums, pivotIndex + 1, right, kSmallest);
}
private int Partition(int[] nums, int left, int right) {
int pivot = nums[right];
int i = left;
for (int j = left; j < right; j++) {
if (nums[j] <= pivot) {

Swap(nums, i, j);

i++;

}
}

Swap(nums, i, right);

return i;
}
private void Swap(int[] nums, int i, int j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}

Follow on:

Explanation:

Quickselect partitions the array like Quicksort and recursively searches for the kth smallest

element. Here, nums.Length - k gives the kth largest.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

int UniquePaths(int m, int n) {
int[,] dp = new int[m, n];
for (int i = 0; i < m; i++) dp[i, 0] = 1;
for (int j = 0; j < n; j++) dp[0, j] = 1;
for (int i = 1; i < m; i++) {
for (int j = 1; j < n; j++) {
dp[i, j] = dp[i - 1, j] + dp[i, j - 1];
}
}
return dp[m - 1, n - 1];
}

Follow on:

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

void BFS(Dictionary<int, List<int>> graph, int start) {

var visited = new HashSet<int>();
var queue = new Queue<int>();

queue.Enqueue(start);

visited.Add(start);

while (queue.Count > 0) {

int node = queue.Dequeue();

Console.WriteLine(node);

foreach (var neighbor in graph[node]) {
if (!visited.Contains(neighbor)) {

visited.Add(neighbor);

queue.Enqueue(neighbor);

}
}
}
}

Explanation:

Classic BFS using a queue and visited set.
Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

public class TreeNode {
public int val;
public TreeNode left, right;
public TreeNode(int x) { val = x; }
}
TreeNode prev = null;
TreeNode head = null;

TreeNode ConvertToDLL(TreeNode root) {

if (root == null) return null;

ConvertToDLL(root.left);

if (prev == null) {
head = root; // first node becomes head

} else {

root.left = prev;

Follow on:

prev.right = root;
}
prev = root;

ConvertToDLL(root.right);

return head;
}

Explanation:

Inorder traversal connects nodes as doubly linked list by linking current with previous node.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

public class MyQueue {
private Stack<int> stackIn = new Stack<int>();
private Stack<int> stackOut = new Stack<int>();

// Enqueue: push into stackIn (O(1))

public void Enqueue(int x) {

stackIn.Push(x);

}

// Dequeue: if stackOut empty, pour all from stackIn to

stackOut, then pop (amortized O(1))

public int Dequeue() {
if (stackOut.Count == 0) {

while (stackIn.Count > 0) {

stackOut.Push(stackIn.Pop());

}
}
return stackOut.Pop();
}
public int Peek() {
if (stackOut.Count == 0) {

while (stackIn.Count > 0) {

stackOut.Push(stackIn.Pop());

}
}
return stackOut.Peek();
}
public bool IsEmpty() {
return stackIn.Count == 0 && stackOut.Count == 0;
}
}

Follow on:

Explanation:

Two stacks are used: stackIn for enqueue, stackOut for dequeue. Elements are

transferred only when needed, making both operations amortized O(1).

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

begins

public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; next = null; }
}
ListNode DetectCycle(ListNode head) {
if (head == null) return null;
ListNode slow = head, fast = head;

Follow on:

// Detect cycle using Floyd's Tortoise and Hare

while (fast != null && fast.next != null) {

slow = slow.next;
fast = fast.next.next;
if (slow == fast) { // cycle detected
ListNode ptr = head;

while (ptr != slow) {

ptr = ptr.next;
slow = slow.next;
}
return ptr; // start node of cycle
}
}
return null; // no cycle
}

Explanation:

First detect cycle meeting point with two pointers. Then find start node by moving one

pointer from head and one from meeting point until they meet.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

substring (needle) in a string (haystack)

int StrStr(string haystack, string needle)
{
if (needle == "") return 0;
int n = haystack.Length, m = needle.Length;
for (int i = 0; i <= n - m; i++)
{
int j;

Follow on:

for (j = 0; j < m; j++)
{
if (haystack[i + j] != needle[j])

break;

}
if (j == m) return i; // found
}
return -1;
}

Explanation:

Simple sliding window check each position; returns starting index or -1.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

int MergeSortAndCount(int[] arr, int[] temp, int left, int right)

int invCount = 0;

if (right > left)

int mid = (right + left) / 2;

invCount += MergeSortAndCount(arr, temp, left, mid);

invCount += MergeSortAndCount(arr, temp, mid + 1, right);

invCount += Merge(arr, temp, left, mid + 1, right);

return invCount;

int Merge(int[] arr, int[] temp, int left, int mid, int right)

int i = left, j = mid, k = left;

int invCount = 0;

while (i <= mid - 1 && j <= right)

if (arr[i] <= arr[j])

temp[k++] = arr[i++];

else

temp[k++] = arr[j++];

invCount += (mid - i); // Count inversions

while (i <= mid - 1)

temp[k++] = arr[i++];

Follow on:

while (j <= right)

temp[k++] = arr[j++];

for (int idx = left; idx <= right; idx++)

arr[idx] = temp[idx];

return invCount;

Explanation:

Using a modified merge sort to count pairs where arr[i] > arr[j] for i < j efficiently.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

Answer: lgorithm int GCD(int a, int b) { Follow on: while (b != 0) { int temp = b; b = a % b; = temp; } return a; } Explanation: Repeatedly replace (a, b) with (b, a mod b) until b is 0; then a is the GCD.

What interviewers expect

  • A clear definition tied to Coding in C# Coding Interview projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production C# Coding Interview application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in C# Coding Interview architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

void QuickSort(int[] arr, int low, int high)

{
if (low < high)

Follow on:

{
int pi = Partition(arr, low, high);

QuickSort(arr, low, pi - 1);

QuickSort(arr, pi + 1, high);

}
}
int Partition(int[] arr, int low, int high)
{
int pivot = arr[high];
int i = low - 1;
for (int j = low; j < high; j++)
{
if (arr[j] < pivot)
{

i++;

(arr[i], arr[j]) = (arr[j], arr[i]);
}
}
(arr[i + 1], arr[high]) = (arr[high], arr[i + 1]);
return i + 1;
}

Explanation:

Choose last element as pivot, partition array so left < pivot < right, recursively sort

subarrays.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

Answer: int Fibonacci(int n) if (n &lt;= 1) return n; int a = 0, b = 1; for (int i = 2; i &lt;= n; i++) int temp = a + b; a = b; b = temp; return b; Explanation: Iterative DP approach; each Fibonacci number is sum of two previous. Follow on:

What interviewers expect

  • A clear definition tied to Coding in C# Coding Interview projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production C# Coding Interview application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in C# Coding Interview architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

Answer: lternative using Brian Kernighan’s algorithm: public int CountSetBits(int n) { int count = 0; while (n != 0) { n &amp;= (n - 1); // Drops the lowest set bit count++; } return count; } Follow on:

What interviewers expect

  • A clear definition tied to Coding in C# Coding Interview projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production C# Coding Interview application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in C# Coding Interview architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

rray.Copy(arr, left, L, 0, n1);

rray.Copy(arr, mid + 1, R, 0, n2);

int i = 0, j = 0, k = left;

while (i < n1 && j < n2)

rr[k++] = (L[i] <= R[j]) ? L[i++] : R[j++];
while (i < n1) arr[k++] = L[i++];
while (j < n2) arr[k++] = R[j++];
}

Explanation:

Divide array, sort left & right halves, then merge sorted halves.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

public int CountOnes(int n) {
int count = 0;

while (n != 0) {

n &= (n - 1); // Drops the lowest set bit

count++;

}
return count;
}

Explanation:

Brian Kernighan’s algorithm efficiently removes the lowest set bit each iteration until zero.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

public string LongestCommonPrefix(string[] strs) {
if (strs == null || strs.Length == 0) return "";
for (int i = 0; i < strs[0].Length; i++) {
char c = strs[0][i];
for (int j = 1; j < strs.Length; j++) {
if (i == strs[j].Length || strs[j][i] != c)
return strs[0].Substring(0, i);
}
}
return strs[0];
}

Follow on:

Explanation:

Check character by character across all strings until mismatch.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

integer

public int CountSetBits(int n) {

int count = 0;

while (n != 0) {

count += n & 1;

n >>= 1;

return count;

Explanation:

Shift through each bit; add 1 to count if least significant bit is set.

Alternative using Brian Kernighan’s algorithm:

public int CountSetBits(int n) {

int count = 0;

while (n != 0) {

n &= (n - 1); // Drops the lowest set bit

count++;

return count;

Follow on:

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

public int[] SortNearlySorted(int[] nums, int k) {
var result = new List<int>();
var minHeap = new SortedSet<(int val, int index)>();
for (int i = 0; i < nums.Length; i++) {

minHeap.Add((nums[i], i));

if (minHeap.Count > k) {
var min = minHeap.Min;

minHeap.Remove(min);

result.Add(min.val);

}
}

while (minHeap.Count > 0) {

var min = minHeap.Min;

minHeap.Remove(min);

result.Add(min.val);

}
return result.ToArray();
}

Explanation:

Use a min-heap of size k+1 to always extract the smallest element in the current window.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

Answer: int ClimbStairs(int n) { if (n &lt;= 2) return n; int a = 1, b = 2; for (int i = 3; i &lt;= n; i++) { int c = a + b; a = b; b = c; return b;

What interviewers expect

  • A clear definition tied to Coding in C# Coding Interview projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production C# Coding Interview application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in C# Coding Interview architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

int CountConnectedComponents(Dictionary<int, List<int>> graph) {
var visited = new HashSet<int>();
int count = 0;

Follow on:

foreach (var node in graph.Keys) {
if (!visited.Contains(node)) {

DFS(node, graph, visited);

count++;

}
}
return count;
}

void DFS(int node, Dictionary<int, List<int>> graph, HashSet<int>

visited) {

visited.Add(node);

foreach (var neighbor in graph[node]) {
if (!visited.Contains(neighbor)) {

DFS(neighbor, graph, visited);

}
}
}

Explanation:

Run DFS on unvisited nodes, count how many times DFS starts.

Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

void VerticalSum(TreeNode root, int hd, Dictionary<int, int> map) {

if (root == null) return;

VerticalSum(root.left, hd - 1, map);

if (map.ContainsKey(hd))
map[hd] += root.val;

else

map[hd] = root.val;

VerticalSum(root.right, hd + 1, map);

}
Dictionary<int, int> GetVerticalSum(TreeNode root) {
var map = new Dictionary<int, int>();

VerticalSum(root, 0, map);

return map;
}

Explanation:

Use horizontal distance (hd) from root; sum values of nodes at each hd.

Follow on:

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