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 1026–1050 of 4608

Career & HR topics

By tech stack

Popular tracks

Mid PDF
Maximum Sum Increasing Subsequence?

Short answer: int MaxSumIncreasingSubsequence(int[] nums) { int n = nums.Length; int[] dp = new int[n]; Array.Copy(nums, dp, n); for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { Follow on: if (nums[i] &g…

Coding Read answer
Mid PDF
Check if a binary tree is a valid BST (with recursion) bool IsValidBST(TreeNode root) { return Validate(root, null, null); } Follow on: bool Validate(TreeNode node, int?

Short answer: min, int? max) { if (node == null) return true; if ((min != null && node.val <= min) || (max != null && node.val >= max)) return false; return Validate(node.left, min, node.val) &&…

Coding Read answer
Mid PDF
Rotate Matrix by 90 Degrees (Clockwise)?

Short answer: void RotateMatrix(int[][] matrix) { Example code int n = matrix.Length; // Transpose for (int i = 0; i < n; i++) for (int j = i; j < n; j++) (matrix[i][j], matrix[j][i]) = (matrix[j][i], matrix[i][j])…

Coding Read answer
Mid PDF
Count Number of 1’s in Binary Representation?

Short answer: 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 removes one set bit per iteration. Ex…

Coding Read answer
Mid PDF
Find kth Smallest Element in a Sorted Matrix?

Short answer: int KthSmallest(int[][] matrix, int k) { int n = matrix.Length; int low = matrix[0][0], high = matrix[n - 1][n - 1]; while (low < high) { Follow on: int mid = low + (high - low) / 2; int count = 0, j = n…

Coding Read answer
Mid PDF
Rod Cutting Problem?

Short answer: int RodCutting(int[] prices, int n) { int[] dp = new int[n + 1]; dp[0] = 0; Follow on: for (int i = 1; i <= n; i++) { int maxVal = int.MinValue; for (int j = 0; j < i; j++) { maxVal = Math.Max(maxVal,…

Coding Read answer
Mid PDF
Find missing number (1 to N)?

Short answer: int[] arr = { 1, 2, 4, 5 }; int n = 5; int expectedSum = n * (n + 1) / 2; int actualSum = 0; foreach (int num in arr) actualSum += num; int missing = expectedSum - actualSum; Example code int[] arr = { 1, 2…

Coding Scenarios Read answer
Mid PDF
Find missing number (1 to N) int[] arr = { 1, 2, 4, 5 }; int n = 5; int expectedSum = n * (n + 1) / 2; int actualSum = 0; foreach (int num in arr)

Short answer: ctualSum += num; int missing = expectedSum - actualSum; ctualSum += num; int missing = expectedSum - actualSum; ctualSum += num; int missing = expectedSum - actualSum; ctualSum += num; int missing = expecte…

Coding Scenarios Read answer
Junior PDF
Basic Calculator (Add, Subtract, Multiply, Divide)?

Short answer: double Calculate(double a, double b, char op) Example code { return op switch { '+' => a + b, Follow on: '-' => a - b, '*' => a * b, '/' => b != 0 ? a / b : throw new DivideByZeroException(), _…

Coding Read answer
Mid PDF
Check if a string has balanced brackets?

Short answer: public bool IsBalanced(string s) { Stack<char> stack = new Stack<char>(); Dictionary<char, char> pairs = new Dictionary<char, char> { {')', '('}, {']', '['}, {'}', '{'} }; foreach (c…

Coding Read answer
Mid PDF
Word Break II (all possible sentences)?

Short answer: List<string> WordBreak(string s, IList<string> wordDict) { Example code var wordSet = new HashSet<string>(wordDict); var memo = new Dictionary<int, List<string>>(); return DFS(…

Coding Read answer
Mid PDF
Find the maximum width of a binary tree?

Short answer: int WidthOfBinaryTree(TreeNode root) { if (root == null) return 0; int maxWidth = 0; Queue<(TreeNode node, int idx)> queue = new Queue<(TreeNode, int)>(); queue.Enqueue((root, 0)); while (queue.…

Coding Read answer
Mid PDF
Solve Sudoku (Backtracking)?

Short answer: bool SolveSudoku(char[][] board) { for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { Follow on: if (board[i][j] == '.') { for (char c = '1'; c <= '9'; c++) { if (IsValid(board, i, j, c))…

Coding Read answer
Junior PDF
Basic Calculator (Add, Subtract, Multiply, Divide) double Calculate(double a, double b, char op) { return op switch { '+' => a + b, Follow on: '-' => a - b, '*' => a * b, '/' => b != 0 ?

Short answer: a / b : throw new DivideByZeroException(), _ => throw new ArgumentException("Invalid operator"), Explanation: Simple switch statement performing basic arithmetic, with divide-by-zero check. Exp…

Coding Read answer
Mid PDF
Sort Array of 0s, 1s, and 2s (Dutch National Flag)?

Short answer: void SortColors(int[] nums) { Example code int low = 0, mid = 0, high = nums.Length - 1; while (mid <= high) { if (nums[mid] == 0) (nums[low++], nums[mid++]) = (nums[mid], nums[low]); else if (nums[mid]…

Coding Read answer
Mid PDF
Matrix Chain Multiplication?

Short answer: int MatrixChainOrder(int[] dims) { int n = dims.Length - 1; int[,] dp = new int[n, n]; for (int l = 2; l <= n; l++) { Follow on: for (int i = 0; i < n - l + 1; i++) { int j = i + l - 1; dp[i, j] = int…

Coding Read answer
Mid PDF
Reverse words in a sentence?

Short answer: string input = "I love dotnet"; string[] words = input.Split(' '); Array.Reverse(words); string result = string.Join(" ", words); Example code string input = "I love dotnet"; s…

Coding Scenarios Read answer
Mid PDF
Reverse words in a sentence string input = "I love dotnet"; string[] words = input.Split(' ');?

Short answer: rray.Reverse(words); string result = string.Join(" ", words); rray.Reverse(words); string result = string.Join(" ", words); rray.Reverse(words); string result = string.Join(" "…

Coding Scenarios Read answer
Mid PDF
Rotate a matrix by 90 degrees in place public void RotateMatrix(int[][] matrix) { int n = matrix.Length; // Transpose for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int temp = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = temp; } } // Reverse each row for (int i = 0; i < n; i++) {

Short answer: rray.Reverse(matrix[i]); } } Explanation: Transpose matrix and then reverse each row to rotate 90° clockwise. Explain a bit more rray.Reverse(matrix[i]); } } Explanation: Transpose matrix and then reverse e…

Coding Read answer
Mid PDF
Rotate a matrix by 90 degrees in place?

Short answer: public void RotateMatrix(int[][] matrix) { int n = matrix.Length; // Transpose for (int i = 0; i &lt; n; i++) { for (int j = i + 1; j &lt; n; j++) { int temp = matrix[i][j]; matrix[i][j] = matrix[j][i]; mat…

Coding Read answer
Mid PDF
Generate Parentheses (Well-formed Combinations)?

Short answer: Follow on: List&lt;string&gt; GenerateParenthesis(int n) if (open &lt; max) Generate(current + &quot;(&quot;, open + 1, close, max, result); if (close &lt; open) Generate(current + &quot;)&quot;, open, clos…

Coding Read answer
Mid PDF
Find Largest Prime Factor of a Number?

Short answer: long LargestPrimeFactor(long n) { Example code long maxPrime = -1; while (n % 2 == 0) { maxPrime = 2; n /= 2; } for (long i = 3; i * i &lt;= n; i += 2) { while (n % i == 0) { maxPrime = i; n /= i; } } if (n…

Coding Read answer
Mid PDF
Find Missing Number in Sorted Array of Distinct?

Short answer: Integers int FindMissingNumber(int[] nums) { int low = 0, high = nums.Length - 1; while (low &lt;= high) { int mid = low + (high - low) / 2; if (nums[mid] == mid) low = mid + 1; else high = mid - 1; } retur…

Coding Read answer
Mid PDF
Partition Problem (Equal Sum Subset)?

Short answer: bool CanPartition(int[] nums) { int sum = nums.Sum(); Follow on: if (sum % 2 != 0) return false; int target = sum / 2; bool[] dp = new bool[target + 1]; dp[0] = true; foreach (int num in nums) { for (int j…

Coding Read answer
Mid PDF
Check palindrome string?

Short answer: bool IsPalindrome(string str) { int left = 0, right = str.Length - 1; while (left &lt; right) { if (str[left] != str[right]) return false; left++; right--; } return true; } Example code bool IsPalindrome(st…

Coding Scenarios Read answer

C# Coding Interview C# Programming Tutorial · Coding

Short answer: int MaxSumIncreasingSubsequence(int[] nums) { int n = nums.Length; int[] dp = new int[n]; Array.Copy(nums, dp, n); for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { Follow on: if (nums[i] > nums[j]) dp[i] = Math.Max(dp[i], dp[j] + nums[i]); } } return dp.Max(); }

Example code

int MaxSumIncreasingSubsequence(int[] nums) {
int n = nums.Length;
int[] dp = new int[n]; Array.Copy(nums, dp, n); for (int i = 1; i < n; i++) {
for (int j = 0; j < i; j++) { Follow on: if (nums[i] > nums[j])
dp[i] = Math.Max(dp[i], dp[j] + nums[i]);
}
}
return dp.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: min, int? max) { if (node == null) return true; if ((min != null && node.val <= min) || (max != null && node.val >= max)) return false; return Validate(node.left, min, node.val) && Validate(node.right, node.val, max); Explanation: Pass down min and max bounds for subtree values; node must be in (min, max) range. min, int? max) {… if (node == null) return…… true; if ((min != null && node.val <= min) || (max != null…

Explain a bit more

&& node.val >= max)) return false; return Validate(node.left, min, node.val) && Validate(node.right, node.val, max); Explanation: Pass down min and max bounds for subtree values; node must be in (min, max) range.

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 RotateMatrix(int[][] matrix) {

Example code

int n = matrix.Length; // Transpose for (int i = 0; i < n; i++)
for (int j = i; j < n; j++) (matrix[i][j], matrix[j][i]) = (matrix[j][i], matrix[i][j]); // Reverse each row for (int i = 0; i < n; i++)
{
int left = 0, right = n - 1; while (left < right) { (matrix[i][left], matrix[i][right]) = (matrix[i][right], matrix[i][left]); left++; right--; }
}
} Explanation: Transpose matrix and then reverse each row to rotate clockwise by 90°.

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 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 removes one set bit per iteration.

Example code

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 removes one set bit per iteration.

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 KthSmallest(int[][] matrix, int k) { int n = matrix.Length; int low = matrix[0][0], high = matrix[n - 1][n - 1]; while (low < high) { Follow on: int mid = low + (high - low) / 2; int count = 0, j = n - 1; for (int i = 0; i < n; i++) { while (j >= 0 && matrix[i][j] > mid) j--; count += (j + 1); } if (count < k) low = mid + 1; else high = mid; } return low; } Explanation: Binary search on values, count how many…

Explain a bit more

elements ≤ mid using matrix’s sorted rows/cols.

Example code

int KthSmallest(int[][] matrix, int k)
{
int n = matrix.Length;
int low = matrix[0][0], high = matrix[n - 1][n - 1]; while (low < high) { Follow on: int mid = low + (high - low) / 2;
int count = 0, j = n - 1;
for (int i = 0; i < n; i++)
{ while (j >= 0 && matrix[i][j] > mid) j--; count += (j + 1);
}
if (count < k)
low = mid + 1; else high = mid;
}
return low;
} Explanation: Binary search on values, count how many elements ≤ mid using matrix’s sorted rows/cols.

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 RodCutting(int[] prices, int n) { int[] dp = new int[n + 1]; dp[0] = 0; Follow on: for (int i = 1; i <= n; i++) { int maxVal = int.MinValue; for (int j = 0; j < i; j++) { maxVal = Math.Max(maxVal, prices[j] + dp[i - j - 1]); } dp[i] = maxVal; } return dp[n]; } Explanation: Max revenue by cutting rod into pieces of various lengths.

Example code

int RodCutting(int[] prices, int n)
{
int[] dp = new int[n + 1];
dp[0] = 0; Follow on: for (int i = 1; i <= n; i++)
{
int maxVal = int.MinValue;
for (int j = 0; j < i; j++)
{
maxVal = Math.Max(maxVal, prices[j] + dp[i - j - 1]);
}
dp[i] = maxVal;
}
return dp[n];
} Explanation: Max revenue by cutting rod into pieces of various lengths.

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: int[] arr = { 1, 2, 4, 5 }; int n = 5; int expectedSum = n * (n + 1) / 2; int actualSum = 0; foreach (int num in arr) actualSum += num; int missing = expectedSum - actualSum;

Example code

int[] arr = { 1, 2, 4, 5 };
int n = 5;
int expectedSum = n * (n + 1) / 2;
int actualSum = 0;
foreach (int num in arr)
actualSum += num;
int missing = expectedSum - actualSum;

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: ctualSum += num; int missing = expectedSum - actualSum; ctualSum += num; int missing = expectedSum - actualSum; ctualSum += num; int missing = expectedSum - actualSum; ctualSum += num; int missing = expectedSum - actualSum;

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: double Calculate(double a, double b, char op)

Example code

{
return op switch
{ '+' => a + b, Follow on: '-' => a - b, '*' => a * b, '/' => b != 0 ? a / b : throw new DivideByZeroException(), _ => throw new ArgumentException("Invalid operator"), }; } Explanation: Simple switch statement performing basic arithmetic, with divide-by-zero check.

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 IsBalanced(string s) { Stack<char> stack = new Stack<char>(); Dictionary<char, char> pairs = new Dictionary<char, char> { {')', '('}, {']', '['}, {'}', '{'} }; foreach (char c in s) { if ("([{".Contains(c)) stack.Push(c); else if (")]}".Contains(c)) { if (stack.Count == 0 || stack.Pop() != pairs[c]) return false; } } return stack.Count == 0; } Follow on: Explanation: Use a stack to match opening and…

Example code

public bool IsBalanced(string s) {
Stack<char> stack = new Stack<char>();
Dictionary<char, char> pairs = new Dictionary<char, char> { {')', '('}, {']', '['}, {'}', '{'} }; foreach (char c in s) {
if ("([{".Contains(c)) stack.Push(c); else if (")]}".Contains(c)) { if (stack.Count == 0 || stack.Pop() != pairs[c])
return false;
}
}
return stack.Count == 0;
} Follow on: Explanation: Use a stack to match opening and closing brackets properly.

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<string> WordBreak(string s, IList<string> wordDict) {

Example code

var wordSet = new HashSet<string>(wordDict);
var memo = new Dictionary<int, List<string>>();
return DFS(0);
List<string> DFS(int start) {
if (memo.ContainsKey(start)) return memo[start];
var res = new List<string>();
if (start == s.Length) { res.Add(""); return res;
}
for (int end = start + 1; end <= s.Length; end++) {
string word = s.Substring(start, end - start);
if (wordSet.Contains(word)) {
foreach (var sub in DFS(end)) {
string space = sub.Length == 0 ? "" : " "; res.Add(word + space + sub); }
}
}
memo[start] = res;
return res;
}
} 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: int WidthOfBinaryTree(TreeNode root) { if (root == null) return 0; int maxWidth = 0; Queue<(TreeNode node, int idx)> queue = new Queue<(TreeNode, int)>(); queue.Enqueue((root, 0)); while (queue.Count > 0) { int size = queue.Count; int start = queue.Peek().idx; int end = start; for (int i = 0; i < size; i++) { var (node, idx) = queue.Dequeue(); end = idx; if (node.left != null) queue.Enqueue((node.left, 2 * idx +…

Explain a bit more

1)); if (node.right != null) queue.Enqueue((node.right, 2 * idx + 2)); } maxWidth = Math.Max(maxWidth, end - start + 1); Follow on: } return maxWidth; } Explanation: Assign index to each node as if in a complete tree; width is max difference of indices per level.

Example code

int WidthOfBinaryTree(TreeNode root) {
if (root == null) return 0;
int maxWidth = 0; Queue<(TreeNode node, int idx)> queue = new Queue<(TreeNode, int)>(); queue.Enqueue((root, 0)); while (queue.Count > 0) { int size = queue.Count;
int start = queue.Peek().idx;
int end = start;
for (int i = 0; i < size; i++) {
var (node, idx) = queue.Dequeue();
end = idx;
if (node.left != null) queue.Enqueue((node.left, 2 * idx + 1)); if (node.right != null) queue.Enqueue((node.right, 2 * idx + 2)); }
maxWidth = Math.Max(maxWidth, end - start + 1); Follow on: }
return maxWidth;
} Explanation: Assign index to each node as if in a complete tree; width is max difference of indices per level.

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 SolveSudoku(char[][] board) { for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { Follow on: if (board[i][j] == '.') { for (char c = '1'; c <= '9'; c++) { if (IsValid(board, i, j, c)) { board[i][j] = c; if (SolveSudoku(board)) return true; else board[i][j] = '.'; } } return false; } } } return true; } bool IsValid(char[][] board, int row, int col, char c) { for (int i = 0; i < 9; i++) { if…

Explain a bit more

(board[row][i] == c) return false; if (board[i][col] == c) return false; if (board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] == c) return false; } return true; } Explanation: Backtracking tries digits 1-9 in empty cells, validating constraints.

Example code

bool SolveSudoku(char[][] board) {
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{ Follow on: if (board[i][j] == '.')
{
for (char c = '1'; c <= '9'; c++)
{
if (IsValid(board, i, j, c))
{
board[i][j] = c;
if (SolveSudoku(board))
return true; else board[i][j] = '.';
}
}
return false;
}
}
}
return true;
} bool IsValid(char[][] board, int row, int col, char c) {
for (int i = 0; i < 9; i++)
{
if (board[row][i] == c) return false;
if (board[i][col] == c) return false;
if (board[3 * (row / 3) + i / 3][3 * (col / 3) + i % 3] == c) return false; }
return true;
} Explanation: Backtracking tries digits 1-9 in empty cells, validating constraints.

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 / b : throw new DivideByZeroException(), _ => throw new ArgumentException("Invalid operator"), Explanation: Simple switch statement performing basic arithmetic, with divide-by-zero check.

Explain a bit more

a / b : throw new DivideByZeroException(), _ => throw new ArgumentException("Invalid operator"), Explanation: Simple switch statement performing basic arithmetic, with divide-by-zero check. a / b : throw new DivideByZeroException(), _ => throw new ArgumentException("Invalid operator"), Explanation: Simple switch statement performing basic arithmetic, with divide-by-zero check.

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 SortColors(int[] nums) {

Example code

int low = 0, mid = 0, high = nums.Length - 1; while (mid <= high) {
if (nums[mid] == 0)
(nums[low++], nums[mid++]) = (nums[mid], nums[low]); else if (nums[mid] == 1) mid++; else (nums[mid], nums[high--]) = (nums[high], nums[mid]);
}
} Follow on: Explanation: Partition array into three parts in one pass using three pointers.

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 MatrixChainOrder(int[] dims) { int n = dims.Length - 1; int[,] dp = new int[n, n]; for (int l = 2; l <= n; l++) { Follow on: for (int i = 0; i < n - l + 1; i++) { int j = i + l - 1; dp[i, j] = int.MaxValue; for (int k = i; k < j; k++) { int cost = dp[i, k] + dp[k + 1, j] + dims[i] * dims[k + 1] * dims[j + 1]; dp[i, j] = Math.Min(dp[i, j], cost); } } } return dp[0, n - 1]; } Explanation: DP calculates minimal…

Explain a bit more

cost to multiply chain of matrices by trying all partitions.

Example code

int MatrixChainOrder(int[] dims)
{
int n = dims.Length - 1;
int[,] dp = new int[n, n];
for (int l = 2; l <= n; l++)
{ Follow on: for (int i = 0; i < n - l + 1; i++)
{
int j = i + l - 1;
dp[i, j] = int.MaxValue;
for (int k = i; k < j; k++)
{
int cost = dp[i, k] + dp[k + 1, j] + dims[i] * dims[k + 1] * dims[j + 1]; dp[i, j] = Math.Min(dp[i, j], cost);
}
}
}
return dp[0, n - 1];
} Explanation: DP calculates minimal cost to multiply chain of matrices by trying all partitions.

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: string input = "I love dotnet"; string[] words = input.Split(' '); Array.Reverse(words); string result = string.Join(" ", words);

Example code

string input = "I love dotnet";
string[] words = input.Split(' '); Array.Reverse(words); string result = string.Join(" ", words);

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: rray.Reverse(words); string result = string.Join(" ", words); rray.Reverse(words); string result = string.Join(" ", words); rray.Reverse(words); string result = string.Join(" ", words); rray.Reverse(words); string result = string.Join(" ", words);

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.Reverse(matrix[i]); } } Explanation: Transpose matrix and then reverse each row to rotate 90° clockwise.

Explain a bit more

rray.Reverse(matrix[i]); } } Explanation: Transpose matrix and then reverse each row to rotate 90° clockwise. rray.Reverse(matrix[i]); } } Explanation: Transpose matrix and then reverse each row to rotate 90° clockwise. rray.Reverse(matrix[i]); } } Explanation: Transpose matrix and then reverse each row to rotate 90° clockwise.

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 RotateMatrix(int[][] matrix) { int n = matrix.Length; // Transpose for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int temp = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = temp; } } // Reverse each row for (int i = 0; i < n; i++) { Array.Reverse(matrix[i]); } } Explanation: Transpose matrix and then reverse each row to rotate 90° clockwise.

Example code

public void RotateMatrix(int[][] matrix) {
int n = matrix.Length; // Transpose for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int temp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = temp;
}
} // Reverse each row for (int i = 0; i < n; i++) { Array.Reverse(matrix[i]); }
} Explanation: Transpose matrix and then reverse each row to rotate 90° clockwise.

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: Follow on: List<string> GenerateParenthesis(int n) if (open < max) Generate(current + "(", open + 1, close, max, result); if (close < open) Generate(current + ")", open, close + 1, max, result); } Explanation: Use backtracking to add '(' and ')' only when valid.

Example code

{
List<string> result = new List<string>(); Generate("", 0, 0, n, result); return result;
} void Generate(string current, int open, int close, int max, List<string> result)
{
if (current.Length == max * 2)
{ result.Add(current); return;
}

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: long LargestPrimeFactor(long n) {

Example code

long maxPrime = -1; while (n % 2 == 0) {
maxPrime = 2;
n /= 2;
}
for (long i = 3; i * i <= n; i += 2)
{ while (n % i == 0) {
maxPrime = i;
n /= i;
}
}
if (n > 2) maxPrime = n;
return maxPrime;
} Follow on: Explanation: Divide out factors of 2, then test odd factors; leftover > 2 is prime. Miscellaneous Problems

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: Integers int FindMissingNumber(int[] nums) { int low = 0, high = nums.Length - 1; while (low <= high) { int mid = low + (high - low) / 2; if (nums[mid] == mid) low = mid + 1; else high = mid - 1; } return low; } Explanation: In perfect array nums[i] == i; missing number breaks this property, use binary search to find breakpoint. Mathematical Problems

Example code

Integers
int FindMissingNumber(int[] nums)
{
int low = 0, high = nums.Length - 1; while (low <= high) {
int mid = low + (high - low) / 2;
if (nums[mid] == mid)
low = mid + 1; else high = mid - 1;
}
return low;
} Explanation: In perfect array nums[i] == i; missing number breaks this property, use binary search to find breakpoint. Mathematical Problems

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 CanPartition(int[] nums) { int sum = nums.Sum(); Follow on: if (sum % 2 != 0) return false; int target = sum / 2; bool[] dp = new bool[target + 1]; dp[0] = true; foreach (int num in nums) { for (int j = target; j >= num; j--) { dp[j] = dp[j] || dp[j - num]; } } return dp[target]; } Explanation: Subset sum to check if half the total sum is achievable. Sorting and Searching

Example code

bool CanPartition(int[] nums) {
int sum = nums.Sum(); Follow on: if (sum % 2 != 0) return false;
int target = sum / 2;
bool[] dp = new bool[target + 1];
dp[0] = true;
foreach (int num in nums)
{
for (int j = target; j >= num; j--)
{
dp[j] = dp[j] || dp[j - num];
}
}
return dp[target];
} Explanation: Subset sum to check if half the total sum is achievable. Sorting and Searching

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: bool IsPalindrome(string str) { int left = 0, right = str.Length - 1; while (left < right) { if (str[left] != str[right]) return false; left++; right--; } return true; }

Example code

bool IsPalindrome(string str) {
int left = 0, right = str.Length - 1; while (left < right) {
if (str[left] != str[right])
return false; left++; right--; }
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
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