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 651–675 of 3281

Career & HR topics

By tech stack

Popular tracks

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 < s.Length) &am…

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

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

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

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…

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 <= 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 <= m; i++) { for (int j = 1; j <= 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 < 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…

Coding Read answer
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

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

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