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 26–50 of 142

Popular tracks

Mid PDF
Find the Longest Palindromic Substring?

Short answer: string LongestPalindrome(string s) { if (string.IsNullOrEmpty(s)) return ""; int start = 0, maxLen = 1; for (int i = 0; i < s.Length; i++) { ExpandAroundCenter(s, i, i, ref start, ref maxLen);…

Coding Read answer
Mid PDF
Least Common Multiple (LCM)?

Short answer: int LCM(int a, int b) { return a / GCD(a, b) * b; } Explanation: LCM × GCD = product of the two numbers. Example code int LCM(int a, int b) { return a / GCD(a, b) * b; } Explanation: LCM × GCD = product of…

Coding Read answer
Mid PDF
Mergesort?

Short answer: void MergeSort(int[] arr, int left, int right) { Example code if (left < right) { int mid = (left + right) / 2; MergeSort(arr, left, mid); MergeSort(arr, mid + 1, right); Follow on: Merge(arr, left, mid,…

Coding Read answer
Mid PDF
0/1 Knapsack Problem?

Short answer: int Knapsack(int[] weights, int[] values, int W) { int n = weights.Length; int[,] dp = new int[n + 1, W + 1]; for (int i = 1; i <= n; i++) { for (int w = 1; w <= W; w++) { if (weights[i - 1] <= w)…

Coding Read answer
Mid PDF
Reverse a string (without built-in reverse)?

Short answer: Logic Convert to char array. Swap characters from both ends. string str = "dotnet"; char[] chars = str.ToCharArray(); int left = 0, right = chars.Length - 1; while (left < right) { char temp =…

Coding Scenarios Read answer
Mid PDF
Calculate power of a number without built-in pow()?

Short answer: public double Power(double x, int n) { if (n == 0) return 1; double half = Power(x, n / 2); if (n % 2 == 0) return half * half; else return n > 0 ? x * half * half : (half * half) / x; } Explanation: Use…

Coding Read answer
Mid PDF
Regular Expression Matching (. and *) bool IsMatch(string s, string p) { return IsMatchHelper(s, p, 0, 0); } bool IsMatchHelper(string s, string p, int i, int j) { if (j == p.Length) return i == s.Length; bool firstMatch = (i < s.Length) && (p[j] == s[i] || p[j] == '.'); if (j + 1 < p.Length && p[j + 1] == '*') { // Two cases: // 1) Use zero occurrence of p[j] (skip) // 2) If firstMatch, consume one char in s and keep pattern

Short answer: t j return IsMatchHelper(s, p, i, j + 2) || (firstMatch &amp;&amp; IsMatchHelper(s, p, i + 1, j)); } else { return firstMatch &amp;&amp; IsMatchHelper(s, p, i + 1, j + 1); } Follow on: } Explanation: Recurs…

Coding Read answer
Mid PDF
Check if two numbers have opposite signs?

Short answer: public bool HaveOppositeSigns(int x, int y) { return (x ^ y) &lt; 0; } Explanation: XOR of two numbers with opposite signs has the sign bit set (negative number). Example code public bool HaveOppositeSigns(…

Coding Read answer
Mid PDF
Implement an iterator for a nested list (flatten a nested list of integers)?

Short answer: public class NestedIterator { private Queue&lt;int&gt; queue; public NestedIterator(IList&lt;NestedInteger&gt; nestedList) { queue = new Queue&lt;int&gt;(); Flatten(nestedList); } private void Flatten(IList…

Coding Read answer
Mid PDF
Calculate power of a number without built-in pow() public double Power(double x, int n) { if (n == 0) return 1; double half = Power(x, n / 2); if (n % 2 == 0) return half * half; else return n > 0 ?

Short answer: x * half * half : (half * half) / x; Explanation: Uses fast exponentiation (divide and conquer) to calculate x^n in O(log n). Explain a bit more x * half * half : (half * half) / x; Explanation: Uses fast e…

Coding Read answer
Mid PDF
Find the median of a data stream?

Short answer: public class MedianFinder { private PriorityQueue&lt;int, int&gt; maxHeap; // lower half (max heap) Follow on: private PriorityQueue&lt;int, int&gt; minHeap; // upper half (min heap) public MedianFinder() {…

Coding Read answer
Mid PDF
House Robber?

Short answer: int HouseRobber(int[] nums) { if (nums.Length == 0) return 0; if (nums.Length == 1) return nums[0]; int prev1 = 0, prev2 = 0; foreach (var num in nums) { int temp = prev1; prev1 = Math.Max(prev2 + num, prev…

Coding Read answer
Mid PDF
Bellman-Ford Algorithm (shortest path from source)?

Short answer: public class Edge { public int Source, Dest, Weight; public Edge(int s, int d, int w) { Source = s; Dest = d; Weight = w; } } int[] BellmanFord(int vertices, List&lt;Edge&gt; edges, int source) { int[] dist…

Coding Read answer
Mid PDF
Flatten a binary tree into a linked list (preorder traversal)?

Short answer: TreeNode prev = null; void Flatten(TreeNode root) { if (root == null) return; Flatten(root.right); Flatten(root.left); root.right = prev; root.left = null; prev = root; } Explanation: Postorder traversal (r…

Coding Read answer
Mid PDF
Find the next greater element for every element in an array?

Short answer: int[] NextGreaterElements(int[] nums) { int n = nums.Length; int[] result = new int[n]; Stack&lt;int&gt; stack = new Stack&lt;int&gt;(); for (int i = n - 1; i &gt;= 0; i--) { while (stack.Count &gt; 0 &amp;…

Coding Read answer
Mid PDF
Merge k sorted linked lists into one sorted linked list?

Short answer: ListNode MergeKLists(ListNode[] lists) { Example code if (lists == null || lists.Length == 0) return null; PriorityQueue&lt;ListNode, int&gt; pq = new PriorityQueue&lt;ListNode, int&gt;(); foreach (var list…

Coding Read answer
Mid PDF
Regular Expression Matching (. and *)?

Short answer: bool IsMatch(string s, string p) { return IsMatchHelper(s, p, 0, 0); } bool IsMatchHelper(string s, string p, int i, int j) { if (j == p.Length) return i == s.Length; bool firstMatch = (i &lt; s.Length) &am…

Coding Read answer
Mid PDF
Find All Subsets (Power Set)?

Short answer: List&lt;List&lt;int&gt;&gt; Subsets(int[] nums) Example code { List&lt;List&lt;int&gt;&gt; result = new List&lt;List&lt;int&gt;&gt;(); GenerateSubsets(nums, 0, new List&lt;int&gt;(), result); return result;…

Coding Read answer
Mid PDF
Check if a Number is Prime?

Short answer: bool IsPrime(int n) { if (n &lt;= 1) return false; if (n &lt;= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i &lt;= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return…

Coding Read answer
Mid PDF
First Occurrence of a Number in a Sorted Array?

Short answer: int FirstOccurrence(int[] arr, int target) { int low = 0, high = arr.Length - 1, result = -1; while (low &lt;= high) { int mid = low + (high - low) / 2; if (arr[mid] == target) { result = mid; Follow on: hi…

Coding Read answer
Mid PDF
Longest Common Subsequence (LCS)?

Short answer: int LCS(string s1, string s2) { int m = s1.Length, n = s2.Length; int[,] dp = new int[m + 1, n + 1]; for (int i = 1; i &lt;= m; i++) { for (int j = 1; j &lt;= n; j++) { if (s1[i - 1] == s2[j - 1]) dp[i, j]…

Coding Read answer
Mid PDF
Find the intersection node of two linked lists (if any)?

Short answer: ListNode GetIntersectionNode(ListNode headA, ListNode headB) { Example code if (headA == null || headB == null) return null; ListNode a = headA, b = headB; while (a != b) { a = (a == null) ? headB : a.next;…

Coding Read answer
Mid PDF
Check if two strings are anagrams?

Short answer: Logic Same length Same character frequency bool IsAnagram(string s1, string s2) { Example code if (s1.Length != s2.Length) return false; int[] count = new int[256]; foreach (char c in s1) count[c]++; foreac…

Coding Scenarios Read answer
Mid PDF
Find the intersection node of two linked lists (if any) ListNode GetIntersectionNode(ListNode headA, ListNode headB) { if (headA == null || headB == null) return null; ListNode a = headA, b = headB; while (a != b) {

Short answer: = (a == null) ? headB : a.next; b = (b == null) ? headA : b.next; } return a; // either intersection or null } Explanation: Two pointers traverse both lists; if no intersection, both will reach null simulta…

Coding Read answer
Mid PDF
Longest Increasing Subsequence (LIS) int LIS(int[] nums) { int n = nums.Length; int[] dp = new int[n];?

Short answer: rray.Fill(dp, 1); int maxLen = 1; for (int i = 1; i &lt; n; i++) { for (int j = 0; j &lt; i; j++) { if (nums[i] &gt; nums[j]) dp[i] = Math.Max(dp[i], dp[j] + 1); } maxLen = Math.Max(maxLen, dp[i]); } return…

Coding Read answer

C# Coding Interview C# Programming Tutorial · Coding

Short answer: string LongestPalindrome(string s) { if (string.IsNullOrEmpty(s)) return ""; int start = 0, maxLen = 1; for (int i = 0; i < s.Length; i++) { ExpandAroundCenter(s, i, i, ref start, ref maxLen); // Odd length palindrome ExpandAroundCenter(s, i, i + 1, ref start, ref maxLen); // Even length palindrome } return s.Substring(start, maxLen); } void ExpandAroundCenter(string s, int left, int right, ref int start, ref int…

Explain a bit more

maxLen) { while (left >= 0 && right < s.Length && s[left] == s[right]) { if (right - left + 1 > maxLen) Follow on: { start = left; maxLen = right - left + 1; } left--; right++; } } Explanation: Expand around each center to find the longest palindrome in O(n²).

Example code

string LongestPalindrome(string s)
{
if (string.IsNullOrEmpty(s)) return "";
int start = 0, maxLen = 1;
for (int i = 0; i < s.Length; i++)
{ ExpandAroundCenter(s, i, i, ref start, ref maxLen); // Odd length palindrome ExpandAroundCenter(s, i, i + 1, ref start, ref maxLen); // Even length palindrome }
return s.Substring(start, maxLen);
} void ExpandAroundCenter(string s, int left, int right, ref int start, ref int maxLen) { while (left >= 0 && right < s.Length && s[left] == s[right]) {
if (right - left + 1 > maxLen) Follow on: {
start = left;
maxLen = right - left + 1;
} left--; right++; }
} Explanation: Expand around each center to find the longest palindrome in O(n²).

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: int LCM(int a, int b) { return a / GCD(a, b) * b; } Explanation: LCM × GCD = product of the two numbers.

Example code

int LCM(int a, int b)
{
return a / GCD(a, b) * b;
} Explanation: LCM × GCD = product of the two numbers.

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: void MergeSort(int[] arr, int left, int right) {

Example code

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]; Array.Copy(arr, left, L, 0, n1); Array.Copy(arr, mid + 1, R, 0, n2); int i = 0, j = 0, k = left; while (i < n1 && j < n2) arr[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.

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: int Knapsack(int[] weights, int[] values, int W) { int n = weights.Length; int[,] dp = new int[n + 1, W + 1]; for (int i = 1; i <= n; i++) { for (int w = 1; w <= W; w++) { if (weights[i - 1] <= w) dp[i, w] = Math.Max(dp[i - 1, w], values[i - 1] + dp[i - 1, w - weights[i - 1]]); else dp[i, w] = dp[i - 1, w]; } } return dp[n, W]; } Explanation: Build table where dp[i,w] = max value using first i items and capacity w.

Example code

int Knapsack(int[] weights, int[] values, int W)
{
int n = weights.Length;
int[,] dp = new int[n + 1, W + 1];
for (int i = 1; i <= n; i++)
{
for (int w = 1; w <= W; w++)
{
if (weights[i - 1] <= w) dp[i, w] = Math.Max(dp[i - 1, w], values[i - 1] + dp[i - 1, w - weights[i - 1]]); else dp[i, w] = dp[i - 1, w];
}
}
return dp[n, W];
} Explanation: Build table where dp[i,w] = max value using first i items and capacity w. Follow on:

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding Scenarios

Short answer: Logic Convert to char array. Swap characters from both ends. string str = "dotnet"; char[] chars = str.ToCharArray(); int left = 0, right = chars.Length - 1; while (left < right) { char temp = chars[left]; chars[left] = chars[right]; chars[right] = temp; left++; right--; } string reversed = new string(chars);

Example code

Logic Convert to char array. Swap characters from both ends. string str = "dotnet";
char[] chars = str.ToCharArray();
int left = 0, right = chars.Length - 1; while (left < right) {
char temp = chars[left];
chars[left] = chars[right];
chars[right] = temp; left++; right--; }
string reversed = new string(chars);

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: public double Power(double x, int n) { if (n == 0) return 1; double half = Power(x, n / 2); if (n % 2 == 0) return half * half; else return n > 0 ? x * half * half : (half * half) / x; } Explanation: Uses fast exponentiation (divide and conquer) to calculate x^n in O(log n).

Example code

public double Power(double x, int n) {
if (n == 0) return 1;
double half = Power(x, n / 2);
if (n % 2 == 0)
return half * half; else return n > 0 ? x * half * half : (half * half) / x;
} Explanation: Uses fast exponentiation (divide and conquer) to calculate x^n in O(log n).

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: t j return IsMatchHelper(s, p, i, j + 2) || (firstMatch && IsMatchHelper(s, p, i + 1, j)); } else { return firstMatch && IsMatchHelper(s, p, i + 1, j + 1); } Follow on: } Explanation: Recursively matches strings supporting '.' (any char) and '*' (zero or more of preceding).

Explain a bit more

t j return IsMatchHelper(s, p, i, j + 2) || (firstMatch && IsMatchHelper(s, p, i + 1, j)); } else { return firstMatch && IsMatchHelper(s, p, i + 1, j + 1); } Follow on: } Explanation: Recursively matches strings supporting '.' (any char) and '*' (zero or more of preceding). t j return IsMatchHelper(s, p, i, j + 2) || (firstMatch && IsMatchHelper(s, p, i + 1, j)); } else { return firstMatch && IsMatchHelper(s, p, i + 1, j + 1); } Follow on: } Explanation: Recursively matches strings supporting '.' (any char) and '*' (zero or more of preceding).

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: public bool HaveOppositeSigns(int x, int y) { return (x ^ y) < 0; } Explanation: XOR of two numbers with opposite signs has the sign bit set (negative number).

Example code

public bool HaveOppositeSigns(int x, int y) {
return (x ^ y) < 0;
} Explanation: XOR of two numbers with opposite signs has the sign bit set (negative number).

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: public class NestedIterator { private Queue<int> queue; public NestedIterator(IList<NestedInteger> nestedList) { queue = new Queue<int>(); Flatten(nestedList); } private void Flatten(IList<NestedInteger> nestedList) { foreach (var ni in nestedList) { if (ni.IsInteger()) queue.Enqueue(ni.GetInteger()); else Flatten(ni.GetList()); } } public bool HasNext() { return queue.Count > 0; } public int Next() { return…

Explain a bit more

queue.Dequeue(); } } Note: NestedInteger is an interface with methods: IsInteger(), GetInteger(), GetList(). Explanation: Pre-flatten the nested list into a queue and iterate over it. Follow on:

Example code

public class NestedIterator {
private Queue<int> queue;
public NestedIterator(IList<NestedInteger> nestedList) {
queue = new Queue<int>(); Flatten(nestedList); }
private void Flatten(IList<NestedInteger> nestedList) {
foreach (var ni in nestedList) {
if (ni.IsInteger()) queue.Enqueue(ni.GetInteger()); else Flatten(ni.GetList()); }
}
public bool HasNext() {
return queue.Count > 0;
}
public int Next() {
return queue.Dequeue();
}
} Note: NestedInteger is an interface with methods: IsInteger(), GetInteger(), GetList(). Explanation: Pre-flatten the nested list into a queue and iterate over it. Follow on:

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: x * half * half : (half * half) / x; Explanation: Uses fast exponentiation (divide and conquer) to calculate x^n in O(log n).

Explain a bit more

x * half * half : (half * half) / x; Explanation: Uses fast exponentiation (divide and conquer) to calculate x^n in O(log n). x * half * half : (half * half) / x; Explanation: Uses fast exponentiation (divide and conquer) to calculate x^n in O(log n). x * half * half : (half * half) / x; Explanation: Uses fast exponentiation (divide and conquer) to calculate x^n in O(log n).

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: public class MedianFinder { private PriorityQueue<int, int> maxHeap; // lower half (max heap) Follow on: private PriorityQueue<int, int> minHeap; // upper half (min heap) public MedianFinder() { maxHeap = new PriorityQueue<int, int>(Comparer<int>.Create((a, b) => b.CompareTo(a))); minHeap = new PriorityQueue<int, int>(); } public void AddNum(int num) { maxHeap.Enqueue(num, num); minHeap.Enqueue(maxHeap.Dequeue(),…

Explain a bit more

maxHeap.Peek()); if (maxHeap.Count < minHeap.Count) maxHeap.Enqueue(minHeap.Dequeue(), minHeap.Peek()); } public double FindMedian() { if (maxHeap.Count > minHeap.Count) return maxHeap.Peek(); return (maxHeap.Peek() + minHeap.Peek()) / 2.0; } } Explanation: Maintain two heaps: maxHeap for lower half, minHeap for upper half. Balance their sizes.

Example code

public class MedianFinder {
private PriorityQueue<int, int> maxHeap; // lower half (max heap) Follow on: private PriorityQueue<int, int> minHeap; // upper half (min heap) public MedianFinder() { maxHeap = new PriorityQueue<int, int>(Comparer<int>.Create((a, b) => b.CompareTo(a)));
minHeap = new PriorityQueue<int, int>();
}
public void AddNum(int num) { maxHeap.Enqueue(num, num); minHeap.Enqueue(maxHeap.Dequeue(), maxHeap.Peek()); if (maxHeap.Count < minHeap.Count) maxHeap.Enqueue(minHeap.Dequeue(), minHeap.Peek()); }
public double FindMedian() {
if (maxHeap.Count > minHeap.Count)
return maxHeap.Peek();
return (maxHeap.Peek() + minHeap.Peek()) / 2.0;
}
} Explanation: Maintain two heaps: maxHeap for lower half, minHeap for upper half. Balance their sizes.

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: int HouseRobber(int[] nums) { if (nums.Length == 0) return 0; if (nums.Length == 1) return nums[0]; int prev1 = 0, prev2 = 0; foreach (var num in nums) { int temp = prev1; prev1 = Math.Max(prev2 + num, prev1); prev2 = temp; } return prev1; }

Example code

int HouseRobber(int[] nums) {
if (nums.Length == 0) return 0;
if (nums.Length == 1) return nums[0];
int prev1 = 0, prev2 = 0;
foreach (var num in nums) {
int temp = prev1;
prev1 = Math.Max(prev2 + num, prev1);
prev2 = temp;
}
return prev1;
}

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: public class Edge { public int Source, Dest, Weight; public Edge(int s, int d, int w) { Source = s; Dest = d; Weight = w; } } int[] BellmanFord(int vertices, List<Edge> edges, int source) { int[] dist = new int[vertices]; for (int i = 0; i < vertices; i++) dist[i] = int.MaxValue; dist[source] = 0; Follow on: for (int i = 1; i < vertices; i++) { foreach (var edge in edges) { if (dist[edge.Source] != int.MaxValue &&…

Explain a bit more

dist[edge.Source] + edge.Weight < dist[edge.Dest]) { dist[edge.Dest] = dist[edge.Source] + edge.Weight; } } } // Detect negative weight cycle (optional) foreach (var edge in edges) { if (dist[edge.Source] != int.MaxValue && dist[edge.Source] + edge.Weight < dist[edge.Dest]) { throw new Exception("Graph contains negative weight cycle"); } } return dist; } Explanation: Relax edges V-1 times, then check for negative weight cycles.

Example code

public class Edge {
public int Source, Dest, Weight;
public Edge(int s, int d, int w) {
Source = s; Dest = d; Weight = w;
}
}
int[] BellmanFord(int vertices, List<Edge> edges, int source) {
int[] dist = new int[vertices];
for (int i = 0; i < vertices; i++) dist[i] = int.MaxValue;
dist[source] = 0; Follow on: for (int i = 1; i < vertices; i++) {
foreach (var edge in edges) {
if (dist[edge.Source] != int.MaxValue && dist[edge.Source] + edge.Weight < dist[edge.Dest]) { dist[edge.Dest] = dist[edge.Source] + edge.Weight;
}
}
} // Detect negative weight cycle (optional) foreach (var edge in edges) {
if (dist[edge.Source] != int.MaxValue && dist[edge.Source] + edge.Weight < dist[edge.Dest]) { throw new Exception("Graph contains negative weight cycle"); }
}
return dist;
} Explanation: Relax edges V-1 times, then check for negative weight cycles.

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: TreeNode prev = null; void Flatten(TreeNode root) { if (root == null) return; Flatten(root.right); Flatten(root.left); root.right = prev; root.left = null; prev = root; } Explanation: Postorder traversal (right-left-root) to flatten tree in place.

Example code

TreeNode prev = null; void Flatten(TreeNode root) { if (root == null) return; Flatten(root.right); Flatten(root.left); root.right = prev;
root.left = null;
prev = root;
} Explanation: Postorder traversal (right-left-root) to flatten tree in place.

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: int[] NextGreaterElements(int[] nums) { int n = nums.Length; int[] result = new int[n]; Stack<int> stack = new Stack<int>(); for (int i = n - 1; i >= 0; i--) { while (stack.Count > 0 && stack.Peek() <= nums[i]) { stack.Pop(); } result[i] = stack.Count == 0 ? -1 : stack.Peek(); stack.Push(nums[i]); } return result; } Explanation: Traverse from right to left, use stack to keep track of next greater elements in O(n).

Example code

int[] NextGreaterElements(int[] nums) {
int n = nums.Length;
int[] result = new int[n];
Stack<int> stack = new Stack<int>();
for (int i = n - 1; i >= 0; i--) { while (stack.Count > 0 && stack.Peek() <= nums[i]) { stack.Pop(); }
result[i] = stack.Count == 0 ? -1 : stack.Peek(); stack.Push(nums[i]); }
return result;
} Explanation: Traverse from right to left, use stack to keep track of next greater elements in O(n).

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: ListNode MergeKLists(ListNode[] lists) {

Example code

if (lists == null || lists.Length == 0) return null; PriorityQueue<ListNode, int> pq = new PriorityQueue<ListNode, int>();
foreach (var list in lists)
if (list != null) pq.Enqueue(list, list.val); ListNode dummy = new ListNode(0);
ListNode current = dummy; while (pq.Count > 0) { var node = pq.Dequeue();
current.next = node;
current = current.next;
if (node.next != null) pq.Enqueue(node.next, node.next.val); }
return dummy.next;
} Follow on: Explanation: Use a min-heap (priority queue) to always pick the smallest head node among k lists.

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: bool IsMatch(string s, string p) { return IsMatchHelper(s, p, 0, 0); } bool IsMatchHelper(string s, string p, int i, int j) { if (j == p.Length) return i == s.Length; bool firstMatch = (i < s.Length) && (p[j] == s[i] || p[j] == '.'); if (j + 1 < p.Length && p[j + 1] == '*') { // Two cases: // 1) Use zero occurrence of p[j] (skip) // 2) If firstMatch, consume one char in s and keep pattern at j return…

Explain a bit more

IsMatchHelper(s, p, i, j + 2) || (firstMatch && IsMatchHelper(s, p, i + 1, j)); } else { return firstMatch && IsMatchHelper(s, p, i + 1, j + 1); } Follow on: } Explanation: Recursively matches strings supporting '.' (any char) and '*' (zero or more of preceding).

Example code

bool IsMatch(string s, string p) {
return IsMatchHelper(s, p, 0, 0);
} bool IsMatchHelper(string s, string p, int i, int j) {
if (j == p.Length) return i == s.Length; bool firstMatch = (i < s.Length) && (p[j] == s[i] || p[j] == '.'); if (j + 1 < p.Length && p[j + 1] == '*')
{ // Two cases: // 1) Use zero occurrence of p[j] (skip) // 2) If firstMatch, consume one char in s and keep pattern at j return IsMatchHelper(s, p, i, j + 2) || (firstMatch && IsMatchHelper(s, p, i + 1, j)); } else {
return firstMatch && IsMatchHelper(s, p, i + 1, j + 1);
} Follow on: } Explanation: Recursively matches strings supporting '.' (any char) and '*' (zero or more of preceding).

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: List<List<int>> Subsets(int[] nums)

Example code

{
List<List<int>> result = new List<List<int>>(); GenerateSubsets(nums, 0, new List<int>(), result); return result;
} void GenerateSubsets(int[] nums, int index, List<int> current, List<List<int>> result)
{
if (index == nums.Length)
{ result.Add(new List<int>(current)); return;
} // Exclude nums[index] GenerateSubsets(nums, index + 1, current, result); // Include nums[index] current.Add(nums[index]); GenerateSubsets(nums, index + 1, current, result); current.RemoveAt(current.Count - 1); Follow on: } Explanation: Backtracking approach includes/excludes each element.

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: bool IsPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; Follow on: } return true; } Explanation: Check divisibility by 2, 3, then test possible divisors of form 6k ± 1 up to √n.

Example code

bool IsPrime(int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i += 6)
{
if (n % i == 0 || n % (i + 2) == 0)
return false; Follow on: }
return true;
} Explanation: Check divisibility by 2, 3, then test possible divisors of form 6k ± 1 up to √n.

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: int FirstOccurrence(int[] arr, int target) { int low = 0, high = arr.Length - 1, result = -1; while (low <= high) { int mid = low + (high - low) / 2; if (arr[mid] == target) { result = mid; Follow on: high = mid - 1; // search left side } else if (arr[mid] < target) low = mid + 1; else high = mid - 1; } return result; } Explanation: Binary search but continue left to find first occurrence.

Example code

int FirstOccurrence(int[] arr, int target)
{
int low = 0, high = arr.Length - 1, result = -1; while (low <= high) {
int mid = low + (high - low) / 2;
if (arr[mid] == target)
{
result = mid; Follow on: high = mid - 1; // search left side
} else if (arr[mid] < target) low = mid + 1; else high = mid - 1;
}
return result;
} Explanation: Binary search but continue left to find first occurrence.

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: int LCS(string s1, string s2) { int m = s1.Length, n = s2.Length; int[,] dp = new int[m + 1, n + 1]; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (s1[i - 1] == s2[j - 1]) dp[i, j] = dp[i - 1, j - 1] + 1; else dp[i, j] = Math.Max(dp[i - 1, j], dp[i, j - 1]); } } return dp[m, n]; } Explanation: Build DP table comparing chars; find longest subsequence common to both strings. Follow on:

Example code

int LCS(string s1, string s2)
{
int m = s1.Length, n = s2.Length;
int[,] dp = new int[m + 1, n + 1];
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= n; j++)
{
if (s1[i - 1] == s2[j - 1])
dp[i, j] = dp[i - 1, j - 1] + 1; else dp[i, j] = Math.Max(dp[i - 1, j], dp[i, j - 1]);
}
}
return dp[m, n];
} Explanation: Build DP table comparing chars; find longest subsequence common to both strings. Follow on:

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: ListNode GetIntersectionNode(ListNode headA, ListNode headB) {

Example code

if (headA == null || headB == null) return null;
ListNode a = headA, b = headB; while (a != b) { a = (a == null) ? headB : a.next;
b = (b == null) ? headA : b.next;
}
return a; // either intersection or null
} Explanation: Two pointers traverse both lists; if no intersection, both will reach null simultaneously.

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding Scenarios

Short answer: Logic Same length Same character frequency bool IsAnagram(string s1, string s2) {

Example code

if (s1.Length != s2.Length) return false;
int[] count = new int[256];
foreach (char c in s1) count[c]++;
foreach (char c in s2) count[c]--;
foreach (int i in count)
if (i != 0) return false;
return true;
}

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: = (a == null) ? headB : a.next; b = (b == null) ? headA : b.next; } return a; // either intersection or null } Explanation: Two pointers traverse both lists; if no intersection, both will reach null simultaneously. = (a == null) ? headB : a.next; b = (b == null) ? headA : b.next; } return a; // either intersection or null }… Explanation: Two pointers…… traverse both lists; if no intersection, both will reach null…

Explain a bit more

simultaneously. = (a == null) ? headB : a.next; b = (b == null) ? headA : b.next; } return a; // either intersection or null } Explanation: Two pointers traverse both lists; if no intersection, both will reach null simultaneously. = (a == null) ? headB : a.next; b = (b == null) ? headA : b.next; } return a; // either intersection or null }… Explanation: Two pointers traverse both lists; if no intersection, both will reach null simultaneously.

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: rray.Fill(dp, 1); int maxLen = 1; for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (nums[i] > nums[j]) dp[i] = Math.Max(dp[i], dp[j] + 1); } maxLen = Math.Max(maxLen, dp[i]); } return maxLen; } Explanation: For each element, find LIS ending there by checking previous smaller elements.

Explain a bit more

Follow on: rray.Fill(dp, 1); int maxLen = 1; for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (nums[i] > nums[j]) dp[i] = Math.Max(dp[i], dp[j] + 1); } maxLen = Math.Max(maxLen, dp[i]); } return maxLen; } Explanation: For each element, find LIS ending there by checking previous smaller elements. for (int i = 1; i < n; i++)

Example code

{
for (int j = 0; j < i; j++)
{
if (nums[i] > nums[j])
dp[i] = Math.Max(dp[i], dp[j] + 1);
}
maxLen = Math.Max(maxLen, dp[i]);
}
return maxLen;
} Explanation: For each element, find LIS ending there by checking previous smaller elements. Follow on:

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

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
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