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 51–75 of 140

Popular tracks

Mid PDF
Find the missing number in a sequence from 1 to n using XOR?

Short answer: public int FindMissingNumber(int[] nums, int n) { int xor = 0; for (int i = 1; i <= n; i++) { xor ^= i; } foreach (int num in nums) { xor ^= num; } return xor; } Follow on: Explanation: XOR all numbers f…

Coding Read answer
Mid PDF
Find the maximum sum path in a triangle (bottom-up DP)?

Short answer: public int MaximumTotal(IList<IList<int>> triangle) { int n = triangle.Count; int[] dp = new int[n]; for (int i = 0; i < n; i++) dp[i] = triangle[n - 1][i]; for (int layer = n - 2; layer >…

Coding Read answer
Mid PDF
Check if a number is a perfect square?

Short answer: public bool IsPerfectSquare(int num) { if (num < 0) return false; int left = 0, right = num; while (left <= right) { int mid = left + (right - left) / 2; long sq = (long)mid * mid; if (sq == num) retu…

Coding Read answer
Mid PDF
Number of ways to partition an array into subsets with equal sum?

Short answer: public int CountPartitions(int[] nums) { int sum = 0; foreach (int num in nums) sum += num; if (sum % 2 != 0) return 0; int target = sum / 2; int[] dp = new int[target + 1]; dp[0] = 1; Follow on: foreach (i…

Coding Read answer
Mid PDF
Longest Palindromic Subsequence?

Short answer: int LongestPalindromeSubseq(string s) { int n = s.Length; int[,] dp = new int[n, n]; for (int i = n - 1; i >= 0; i--) { dp[i, i] = 1; for (int j = i + 1; j < n; j++) { if (s[i] == s[j]) Follow on: dp[…

Coding Read answer
Mid PDF
Find all strongly connected components (Tarjan's Algorithm)?

Short answer: List<List<int>> TarjanSCC(Dictionary<int, List<int>> graph) { Example code int time = 0; var stack = new Stack<int>(); var onStack = new HashSet<int>(); var low = new Dic…

Coding Read answer
Mid PDF
Check if two trees are identical?

Short answer: bool IsIdentical(TreeNode p, TreeNode q) { if (p == null && q == null) return true; if (p == null || q == null) return false; if (p.val != q.val) return false; return IsIdentical(p.left, q.left) &am…

Coding Read answer
Mid PDF
Design a stack to support push, pop, and retrieving the minimum?

Short answer: element in constant time public class MinStack { Example code private Stack<int> stack = new Stack<int>(); private Stack<int> minStack = new Stack<int>(); Follow on: public void Push…

Coding 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) { a = (a == null) ?

Short answer: 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. headB : a.n…

Coding Read answer
Mid PDF
Solve N-Queens Problem?

Short answer: List<List<string>> SolveNQueens(int n) List<string> GenerateBoard(int[] board, int n) Example code { List<List<string>> results = new List<List<string>>(); int[] bo…

Coding Read answer
Mid PDF
Find Peak Element?

Short answer: int FindPeakElement(int[] nums) { int left = 0, right = nums.Length - 1; while (left < right) { int mid = (left + right) / 2; if (nums[mid] > nums[mid + 1]) right = mid; else left = mid + 1; } return…

Coding Read answer
Mid PDF
Longest Increasing Subsequence (LIS)?

Short answer: int LIS(int[] nums) { int n = nums.Length; int[] dp = new int[n]; Array.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.…

Coding Read answer
Mid PDF
Second highest number in array?

Short answer: Logic Track highest and second highest in one loop. int[] arr = { 10, 5, 20, 8 }; int first = int.MinValue, second = int.MinValue; foreach (int num in arr) { if (num > first) { second = first; first = nu…

Coding Scenarios Read answer
Mid PDF
Swap two numbers without using a temporary variable public void Swap(ref int a, ref int b) { if (a != b) {?

Short answer: ^= b; b ^= a; ^= b; } } Explanation: XOR swap algorithm exchanges values without extra storage. Explain a bit more (Check a != b to avoid zeroing when both are same.) ^= b; b ^= a; ^= b; } } Explanation: XO…

Coding Read answer
Mid PDF
Find gcd and lcm of two numbers public int GCD(int a, int b) { Follow on: while (b != 0) { int temp = b; b = a % b;?

Short answer: = temp; } return a; } public int LCM(int a, int b) { return (a / GCD(a, b)) * b; } Explanation: GCD uses Euclidean algorithm. Explain a bit more LCM calculated via LCM(a,b) = (a*b)/GCD(a,b). = temp; } retur…

Coding Read answer
Mid PDF
Swap two numbers without using a temporary variable?

Short answer: public void Swap(ref int a, ref int b) { if (a != b) { a ^= b; b ^= a; a ^= b; } } Explanation: XOR swap algorithm exchanges values without extra storage. (Check a != b to avoid zeroing when both are same.)…

Coding Read answer
Mid PDF
Solve the "Find the Celebrity" problem?

Short answer: public int FindCelebrity(int n, Func<int, int, bool> knows) { int candidate = 0; for (int i = 1; i < n; i++) { if (knows(candidate, i)) candidate = i; } for (int i = 0; i < n; i++) { if (i != ca…

Coding Read answer
Mid PDF
Find gcd and lcm of two numbers?

Short answer: public int GCD(int a, int b) { Follow on: while (b != 0) { int temp = b; b = a % b; a = temp; } return a; } public int LCM(int a, int b) { return (a / GCD(a, b)) * b; } Explanation: GCD uses Euclidean algor…

Coding Read answer
Mid PDF
Find the missing element in an unsorted array where every element?

Short answer: appears twice except one public int SingleNumber(int[] nums) { Example code int result = 0; foreach (var num in nums) { result ^= num; } return result; } Explanation: XOR of all elements cancels duplicates,…

Coding Read answer
Mid PDF
Minimum Path Sum in a grid?

Short answer: int MinPathSum(int[][] grid) { int m = grid.Length, n = grid[0].Length; for (int i = 1; i < m; i++) grid[i][0] += grid[i - 1][0]; for (int j = 1; j < n; j++) grid[0][j] += grid[0][j - 1]; for (int i =…

Coding Read answer
Mid PDF
Dijkstra's Algorithm for shortest path?

Short answer: int[] Dijkstra(Dictionary<int, List<(int neighbor, int weight)>> graph, int source, int vertices) { int[] dist = new int[vertices]; for (int i = 0; i < vertices; i++) dist[i] = int.MaxValue;…

Coding Read answer
Mid PDF
Find the distance between two nodes in a binary tree?

Short answer: TreeNode LCA(TreeNode root, int n1, int n2) { if (root == null) return null; if (root.val == n1 || root.val == n2) return root; TreeNode left = LCA(root.left, n1, n2); Follow on: TreeNode right = LCA(root.r…

Coding Read answer
Mid PDF
Implement sliding window maximum (using a deque)?

Short answer: for (int i = 0; i < n; i++) { // Remove indices out of window if (deque.Count > 0 && deque.First.Value <= i - k) Follow on: deque.RemoveFirst(); // Remove smaller values from the back while…

Coding Read answer
Mid PDF
Add two numbers represented by linked lists (each node contains a digit) ListNode AddTwoNumbers(ListNode l1, ListNode l2) { ListNode dummy = new ListNode(0); ListNode curr = dummy; int carry = 0; while (l1 != null || l2 != null || carry != 0) { int x = (l1 != null) ?

Short answer: l1.val : 0; int y = (l2 != null) ? l2.val : 0; int sum = x + y + carry; carry = sum / 10; curr.next = new ListNode(sum % 10); curr = curr.next; if (l1 != null) l1 = l1.next; if (l2 != null) l2 = l2.next; Fo…

Coding Read answer
Mid PDF
Check if a String is Rotation of Another String?

Short answer: bool IsRotation(string s1, string s2) { if (s1.Length != s2.Length) return false; string doubled = s1 + s1; return doubled.Contains(s2); } Follow on: Explanation: If s2 is rotation of s1, it must be substri…

Coding Read answer

C# Coding Interview C# Programming Tutorial · Coding

Short answer: public int FindMissingNumber(int[] nums, int n) { int xor = 0; for (int i = 1; i <= n; i++) { xor ^= i; } foreach (int num in nums) { xor ^= num; } return xor; } Follow on: Explanation: XOR all numbers from 1 to n and XOR all elements in array; duplicates cancel out, leaving missing number.

Example code

public int FindMissingNumber(int[] nums, int n) {
int xor = 0;
for (int i = 1; i <= n; i++) {
xor ^= i;
}
foreach (int num in nums) {
xor ^= num;
}
return xor;
} Follow on: Explanation: XOR all numbers from 1 to n and XOR all elements in array; duplicates cancel out, leaving missing 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 int MaximumTotal(IList<IList<int>> triangle) { int n = triangle.Count; int[] dp = new int[n]; for (int i = 0; i < n; i++) dp[i] = triangle[n - 1][i]; for (int layer = n - 2; layer >= 0; layer--) { for (int i = 0; i <= layer; i++) { dp[i] = triangle[layer][i] + Math.Max(dp[i], dp[i + 1]); } } return dp[0]; } Explanation: Start from bottom row, keep updating max path sums up to the top.

Example code

public int MaximumTotal(IList<IList<int>> triangle) {
int n = triangle.Count;
int[] dp = new int[n];
for (int i = 0; i < n; i++) dp[i] = triangle[n - 1][i];
for (int layer = n - 2; layer >= 0; layer--) {
for (int i = 0; i <= layer; i++) {
dp[i] = triangle[layer][i] + Math.Max(dp[i], dp[i + 1]);
}
}
return dp[0];
} Explanation: Start from bottom row, keep updating max path sums up to the top.

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 IsPerfectSquare(int num) { if (num < 0) return false; int left = 0, right = num; while (left <= right) { int mid = left + (right - left) / 2; long sq = (long)mid * mid; if (sq == num) return true; else if (sq < num) left = mid + 1; else right = mid - 1; } return false; } Explanation: Binary search for integer square root and check if square equals num.

Example code

public bool IsPerfectSquare(int num) {
if (num < 0) return false;
int left = 0, right = num; while (left <= right) { int mid = left + (right - left) / 2;
long sq = (long)mid * mid;
if (sq == num) return true;
else if (sq < num) left = mid + 1;
else right = mid - 1;
}
return false;
} Explanation: Binary search for integer square root and check if square equals num.

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 int CountPartitions(int[] nums) { int sum = 0; foreach (int num in nums) sum += num; if (sum % 2 != 0) return 0; int target = sum / 2; int[] dp = new int[target + 1]; dp[0] = 1; Follow on: foreach (int num in nums) { for (int j = target; j >= num; j--) { dp[j] += dp[j - num]; } } return dp[target]; } Explanation: Classic subset sum DP. dp[j] = ways to get sum j. Counting subsets summing to half the total.

Example code

public int CountPartitions(int[] nums) {
int sum = 0;
foreach (int num in nums) sum += num;
if (sum % 2 != 0) return 0;
int target = sum / 2;
int[] dp = new int[target + 1];
dp[0] = 1; Follow on: foreach (int num in nums) {
for (int j = target; j >= num; j--) {
dp[j] += dp[j - num];
}
}
return dp[target];
} Explanation: Classic subset sum DP. dp[j] = ways to get sum j. Counting subsets summing to half the total.

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 LongestPalindromeSubseq(string s) { int n = s.Length; int[,] dp = new int[n, n]; for (int i = n - 1; i >= 0; i--) { dp[i, i] = 1; for (int j = i + 1; j < n; j++) { if (s[i] == s[j]) Follow on: dp[i, j] = dp[i + 1, j - 1] + 2; else dp[i, j] = Math.Max(dp[i + 1, j], dp[i, j - 1]); } } return dp[0, n - 1]; }

Example code

int LongestPalindromeSubseq(string s) {
int n = s.Length;
int[,] dp = new int[n, n];
for (int i = n - 1; i >= 0; i--) {
dp[i, i] = 1;
for (int j = i + 1; j < n; j++) {
if (s[i] == s[j]) Follow on: dp[i, j] = dp[i + 1, j - 1] + 2; else dp[i, j] = Math.Max(dp[i + 1, j], dp[i, j - 1]);
}
}
return dp[0, n - 1];
}

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>> TarjanSCC(Dictionary<int, List<int>> graph) {

Example code

int time = 0;
var stack = new Stack<int>();
var onStack = new HashSet<int>();
var low = new Dictionary<int, int>();
var disc = new Dictionary<int, int>();
var visited = new HashSet<int>();
var sccList = new List<List<int>>(); void DFS(int u) { disc[u] = time; Follow on: low[u] = time; time++; stack.Push(u); onStack.Add(u); visited.Add(u); foreach (var v in graph[u]) {
if (!disc.ContainsKey(v)) { DFS(v); low[u] = Math.Min(low[u], low[v]); } else if (onStack.Contains(v)) { low[u] = Math.Min(low[u], disc[v]);
}
}
if (low[u] == disc[u]) {
var scc = new List<int>();
int w; do { w = stack.Pop(); onStack.Remove(w); scc.Add(w); } while (w != u); sccList.Add(scc); }
}
foreach (var node in graph.Keys) {
if (!disc.ContainsKey(node)) DFS(node); }
return sccList;
} Explanation: Tarjan's algorithm finds SCCs using low-link values and DFS stack. 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: bool IsIdentical(TreeNode p, TreeNode q) { if (p == null && q == null) return true; if (p == null || q == null) return false; if (p.val != q.val) return false; return IsIdentical(p.left, q.left) && IsIdentical(p.right, q.right); } Explanation: Recursive check values and structure for equality.

Example code

bool IsIdentical(TreeNode p, TreeNode q) { if (p == null && q == null) return true;
if (p == null || q == null) return false;
if (p.val != q.val) return false;
return IsIdentical(p.left, q.left) && IsIdentical(p.right, q.right); } Explanation: Recursive check values and structure for equality.

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: element in constant time public class MinStack {

Example code

private Stack<int> stack = new Stack<int>();
private Stack<int> minStack = new Stack<int>(); Follow on: public void Push(int x) { stack.Push(x); if (minStack.Count == 0 || x <= minStack.Peek()) minStack.Push(x); }
public void Pop() {
if (stack.Peek() == minStack.Peek()) minStack.Pop(); stack.Pop(); }
public int Top() {
return stack.Peek();
}
public int GetMin() {
return minStack.Peek();
}
} Explanation: Use two stacks: one normal stack, one for minimum values. When pushing a smaller or equal value, push it on minStack; when popping, pop minStack if needed.

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: 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. 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. headB : a.next; b = (b ==…

Explain a bit more

null) ? headA : b.next; return a; // either intersection or null Explanation: Two pointers traverse both lists; if no intersection, both will reach null simultaneously. 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. 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. headB : a.next; b = (b == null) ? headA : b.next; return a; // either intersection…

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<string>> SolveNQueens(int n) List<string> GenerateBoard(int[] board, int n)

Example code

{
List<List<string>> results = new List<List<string>>();
int[] board = new int[n]; // board[i] = column position of queen in row i Solve(0, board, results, n); return results;
} void Solve(int row, int[] board, List<List<string>> results, int n) {
if (row == n)
{ results.Add(GenerateBoard(board, n)); return;
}
for (int col = 0; col < n; col++)
{
if (IsSafe(row, col, board))
{
board[row] = col; Solve(row + 1, board, results, n); }
}
} bool IsSafe(int row, int col, int[] board) {
for (int i = 0; i < row; i++) Follow on: {
if (board[i] == col || Math.Abs(board[i] - col) == Math.Abs(i - row)) return false;
}
return true;
}
{
List<string> res = new List<string>();
for (int i = 0; i < n; i++)
{
char[] row = new char[n];
for (int j = 0; j < n; j++)
row[j] = '.';
row[board[i]] = 'Q'; res.Add(new string(row)); }
return res;
} Explanation: Backtracking places queens row by row while checking columns and diagonals.

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 FindPeakElement(int[] nums) { int left = 0, right = nums.Length - 1; while (left < right) { int mid = (left + right) / 2; if (nums[mid] > nums[mid + 1]) right = mid; else left = mid + 1; } return left; } Explanation: Binary search comparing mid element with right neighbor to find peak.

Example code

int FindPeakElement(int[] nums)
{
int left = 0, right = nums.Length - 1; while (left < right) {
int mid = (left + right) / 2;
if (nums[mid] > nums[mid + 1])
right = mid; else left = mid + 1;
}
return left;
} Explanation: Binary search comparing mid element with right neighbor to find peak.

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 LIS(int[] nums) { int n = nums.Length; int[] dp = new int[n]; Array.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. Follow on:

Example code

int LIS(int[] nums)
{
int n = nums.Length;
int[] dp = new int[n]; Array.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. 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 Track highest and second highest in one loop. int[] arr = { 10, 5, 20, 8 }; int first = int.MinValue, second = int.MinValue; foreach (int num in arr) { if (num > first) { second = first; first = num; } else if (num > second && num != first) { second = num; } }

Example code

Logic Track highest and second highest in one loop. int[] arr = { 10, 5, 20, 8 };
int first = int.MinValue, second = int.MinValue;
foreach (int num in arr)
{
if (num > first)
{
second = first;
first = num;
} else if (num > second && num != first) {
second = num;
}
}

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: ^= b; b ^= a; ^= b; } } Explanation: XOR swap algorithm exchanges values without extra storage.

Explain a bit more

(Check a != b to avoid zeroing when both are same.) ^= b; b ^= a; ^= b; } } Explanation: XOR swap algorithm exchanges values without extra storage. (Check a != b to avoid zeroing when both are same.) ^= b; b ^= a; ^= b; } } Explanation: XOR swap algorithm exchanges values without extra storage. (Check a != b to avoid zeroing when both are same.) ^= b; b ^= a; ^= b; } } Explanation: XOR swap algorithm exchanges values without extra storage. (Check a != b to avoid zeroing when both are same.)

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: = temp; } return a; } public int LCM(int a, int b) { return (a / GCD(a, b)) * b; } Explanation: GCD uses Euclidean algorithm.

Explain a bit more

LCM calculated via LCM(a,b) = (a*b)/GCD(a,b). = temp; } return a; } public int LCM(int a, int b) { return (a / GCD(a, b)) * b; } Explanation: GCD uses Euclidean algorithm. LCM calculated via LCM(a,b) = (a*b)/GCD(a,b). = temp; } return a; } public int LCM(int a, int b) { return (a / GCD(a, b)) * b; } Explanation: GCD uses Euclidean algorithm. LCM calculated via LCM(a,b) = (a*b)/GCD(a,b). = temp; } return a; } public int LCM(int a, int b) { return (a / GCD(a, b)) * b; } Explanation: GCD uses Euclidean algorithm. LCM calculated via LCM(a,b) = (a*b)/GCD(a,b).

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 void Swap(ref int a, ref int b) { if (a != b) { a ^= b; b ^= a; a ^= b; } } Explanation: XOR swap algorithm exchanges values without extra storage. (Check a != b to avoid zeroing when both are same.)

Example code

public void Swap(ref int a, ref int b) {
if (a != b) {
a ^= b;
b ^= a;
a ^= b;
}
} Explanation: XOR swap algorithm exchanges values without extra storage. (Check a != b to avoid zeroing when both are same.)

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 int FindCelebrity(int n, Func<int, int, bool> knows) { int candidate = 0; for (int i = 1; i < n; i++) { if (knows(candidate, i)) candidate = i; } for (int i = 0; i < n; i++) { if (i != candidate && (knows(candidate, i) || !knows(i, candidate))) return -1; } return candidate; } Explanation: First find candidate by elimination, then verify candidate. Follow on:

Example code

public int FindCelebrity(int n, Func<int, int, bool> knows) {
int candidate = 0;
for (int i = 1; i < n; i++) {
if (knows(candidate, i)) candidate = i;
}
for (int i = 0; i < n; i++) {
if (i != candidate && (knows(candidate, i) || !knows(i, candidate))) return -1;
}
return candidate;
} Explanation: First find candidate by elimination, then verify candidate. 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: public int GCD(int a, int b) { Follow on: while (b != 0) { int temp = b; b = a % b; a = temp; } return a; } public int LCM(int a, int b) { return (a / GCD(a, b)) * b; } Explanation: GCD uses Euclidean algorithm. LCM calculated via LCM(a,b) = (a*b)/GCD(a,b).

Example code

public int GCD(int a, int b) { Follow on: while (b != 0) { int temp = b;
b = a % b;
a = temp;
}
return a;
}
public int LCM(int a, int b) {
return (a / GCD(a, b)) * b;
} Explanation: GCD uses Euclidean algorithm. LCM calculated via LCM(a,b) = (a*b)/GCD(a,b).

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: appears twice except one public int SingleNumber(int[] nums) {

Example code

int result = 0;
foreach (var num in nums) {
result ^= num;
}
return result;
} Explanation: XOR of all elements cancels duplicates, leaving the single unique 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: int MinPathSum(int[][] grid) { int m = grid.Length, n = grid[0].Length; for (int i = 1; i < m; i++) grid[i][0] += grid[i - 1][0]; for (int j = 1; j < n; j++) grid[0][j] += grid[0][j - 1]; for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) { grid[i][j] += Math.Min(grid[i - 1][j], grid[i][j - 1]); } } return grid[m - 1][n - 1]; }

Example code

int MinPathSum(int[][] grid) {
int m = grid.Length, n = grid[0].Length;
for (int i = 1; i < m; i++) grid[i][0] += grid[i - 1][0];
for (int j = 1; j < n; j++) grid[0][j] += grid[0][j - 1];
for (int i = 1; i < m; i++) {
for (int j = 1; j < n; j++) {
grid[i][j] += Math.Min(grid[i - 1][j], grid[i][j - 1]);
}
}
return grid[m - 1][n - 1];
}

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[] Dijkstra(Dictionary<int, List<(int neighbor, int weight)>> graph, int source, int vertices) { int[] dist = new int[vertices]; for (int i = 0; i < vertices; i++) dist[i] = int.MaxValue; dist[source] = 0; var pq = new SortedSet<(int dist, int node)>(); pq.Add((0, source)); while (pq.Count > 0) { var current = pq.Min; pq.Remove(current); int u = current.node; foreach (var (v, w) in graph[u]) { if (dist[u] + w <…

Explain a bit more

dist[v]) { if (dist[v] != int.MaxValue) pq.Remove((dist[v], v)); dist[v] = dist[u] + w; pq.Add((dist[v], v)); } } } return dist; } Explanation: Uses a priority queue to pick node with min dist; relax edges.

Example code

int[] Dijkstra(Dictionary<int, List<(int neighbor, int weight)>> graph, int source, int vertices) { int[] dist = new int[vertices];
for (int i = 0; i < vertices; i++) dist[i] = int.MaxValue;
dist[source] = 0;
var pq = new SortedSet<(int dist, int node)>(); pq.Add((0, source)); while (pq.Count > 0) { var current = pq.Min; pq.Remove(current); int u = current.node;
foreach (var (v, w) in graph[u]) {
if (dist[u] + w < dist[v]) {
if (dist[v] != int.MaxValue) pq.Remove((dist[v], v)); dist[v] = dist[u] + w; pq.Add((dist[v], v)); }
}
}
return dist;
} Explanation: Uses a priority queue to pick node with min dist; relax edges.

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 LCA(TreeNode root, int n1, int n2) { if (root == null) return null; if (root.val == n1 || root.val == n2) return root; TreeNode left = LCA(root.left, n1, n2); Follow on: TreeNode right = LCA(root.right, n1, n2); if (left != null && right != null) return root; return left ??

Explain a bit more

right; } int FindLevel(TreeNode root, int val, int level) { if (root == null) return -1; if (root.val == val) return level; int left = FindLevel(root.left, val, level + 1); if (left != -1) return left; return FindLevel(root.right, val, level + 1); } int DistanceBetweenNodes(TreeNode root, int n1, int n2) { TreeNode lca = LCA(root, n1, n2); int d1 = FindLevel(lca, n1, 0); int d2 = FindLevel(lca, n2, 0); return d1 + d2; } Explanation: Find Lowest Common Ancestor (LCA) then sum distances from LCA to each node.

Example code

TreeNode LCA(TreeNode root, int n1, int n2) { if (root == null) return null;
if (root.val == n1 || root.val == n2) return root;
TreeNode left = LCA(root.left, n1, n2); Follow on: TreeNode right = LCA(root.right, n1, n2);
if (left != null && right != null) return root;
return left ?? right;
}
int FindLevel(TreeNode root, int val, int level) {
if (root == null) return -1;
if (root.val == val) return level;
int left = FindLevel(root.left, val, level + 1);
if (left != -1) return left;
return FindLevel(root.right, val, level + 1);
}
int DistanceBetweenNodes(TreeNode root, int n1, int n2) {
TreeNode lca = LCA(root, n1, n2);
int d1 = FindLevel(lca, n1, 0);
int d2 = FindLevel(lca, n2, 0);
return d1 + d2;
} Explanation: Find Lowest Common Ancestor (LCA) then sum distances from LCA to each node.

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: for (int i = 0; i < n; i++) { // Remove indices out of window if (deque.Count > 0 && deque.First.Value <= i - k) Follow on: deque.RemoveFirst(); // Remove smaller values from the back while (deque.Count > 0 && nums[deque.Last.Value] < nums[i]) deque.RemoveLast(); deque.AddLast(i); if (i >= k - 1)

Example code

public int[] MaxSlidingWindow(int[] nums, int k) {
if (nums == null || k <= 0) return new int[0];
int n = nums.Length;
int[] result = new int[n - k + 1];
LinkedList<int> deque = new LinkedList<int>(); // store indices
result[i - k + 1] = nums[deque.First.Value];
}
return result;
} Explanation: Use a deque to keep indexes of useful elements in current window, ensuring the front is always max.

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: l1.val : 0; int y = (l2 != null) ? l2.val : 0; int sum = x + y + carry; carry = sum / 10; curr.next = new ListNode(sum % 10); curr = curr.next; if (l1 != null) l1 = l1.next; if (l2 != null) l2 = l2.next; Follow on: return dummy.next; Explanation: Add digit by digit with carry, creating new nodes for the result. l1.val : 0; int y = (l2 != null) ? l2.val :… 0;… int sum = x + y + carry; carry = sum / 10; curr.next =…

Explain a bit more

new ListNode(sum % 10); curr = curr.next; if (l1 != null) l1 = l1.next; if (l2 != null) l2 = l2.next; Follow on: return dummy.next; Explanation: Add digit by digit with carry, creating new nodes for the result.

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 IsRotation(string s1, string s2) { if (s1.Length != s2.Length) return false; string doubled = s1 + s1; return doubled.Contains(s2); } Follow on: Explanation: If s2 is rotation of s1, it must be substring of s1+s1.

Example code

bool IsRotation(string s1, string s2) {
if (s1.Length != s2.Length) return false;
string doubled = s1 + s1;
return doubled.Contains(s2);
} Follow on: Explanation: If s2 is rotation of s1, it must be substring of s1+s1.

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