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 701–725 of 3281

Career & HR topics

By tech stack

Popular tracks

Mid PDF
Find Element that Appears Once in Sorted Array?

Short answer: (Others Appear Twice) int SingleNonDuplicate(int[] nums) Example code { int low = 0, high = nums.Length - 1; while (low < high) { int mid = low + (high - low) / 2; if (mid % 2 == 1) mid--; // ensure mid…

Coding Read answer
Mid PDF
Word Break Problem?

Short answer: bool WordBreak(string s, HashSet<string> wordDict) { bool[] dp = new bool[s.Length + 1]; dp[0] = true; for (int i = 1; i <= s.Length; i++) { for (int j = 0; j < i; j++) { if (dp[j] && wo…

Coding Read answer
Mid PDF
Find all duplicate characters in a string?

Short answer: string input = "programming"; Dictionary<char, int> map = new Dictionary<char, int>(); foreach (char c in input) map[c] = map.ContainsKey(c) ? map[c] + 1 : 1; foreach (var item in map)…

Coding Scenarios Read answer
Mid PDF
Find Majority Element (More than n/2 times)?

Short answer: int MajorityElement(int[] nums) { int count = 0, candidate = 0; foreach (var num in nums) { if (count == 0) candidate = num; count += (num == candidate) ? 1 : -1; } return candidate; } Explanation: Boyer-Mo…

Coding Read answer
Mid PDF
Power of a Number (x^n) — Fast Exponentiation?

Short answer: double Power(double x, int n) Follow on: { Example code if (n == 0) return 1; double temp = Power(x, n / 2); if (n % 2 == 0) return temp * temp; else return (n > 0) ? x * temp * temp : (temp * temp) / x;…

Coding Read answer
Mid PDF
Find Majority Element (Boyer-Moore Voting?

Short answer: Algorithm) int MajorityElement(int[] nums) Example code { int count = 0, candidate = 0; foreach (var num in nums) { if (count == 0) candidate = num; count += (num == candidate) ? 1 : -1; } return candidate;…

Coding Read answer
Mid PDF
Solve "Find the Duplicate Number" problem in an array of n+1 integers?

Short answer: public int FindDuplicate(int[] nums) { int slow = nums[0], fast = nums[0]; do { slow = nums[slow]; fast = nums[nums[fast]]; } while (slow != fast); fast = nums[0]; while (slow != fast) { slow = nums[slow];…

Coding Read answer
Mid PDF
Palindrome Partitioning (minimum cuts)?

Short answer: int MinCutPalindromePartition(string s) { int n = s.Length; bool[,] dp = new bool[n, n]; int[] cuts = new int[n]; for (int i = 0; i < n; i++) { int minCuts = i; for (int j = 0; j <= i; j++) { if (s[j]…

Coding Read answer
Mid PDF
Print all ancestors of a given node in a binary tree?

Short answer: bool PrintAncestors(TreeNode root, int target) { if (root == null) return false; if (root.val == target) return true; if (PrintAncestors(root.left, target) || PrintAncestors(root.right, target)) { Console.W…

Coding Read answer
Mid PDF
Find Majority Element (More than n/2 times) int MajorityElement(int[] nums) { int count = 0, candidate = 0; foreach (var num in nums) { if (count == 0) candidate = num; count += (num == candidate) ?

Short answer: 1 : -1; return candidate; Explanation: Boyer-Moore Voting Algorithm tracks majority element by counting net votes. Follow on: Real-world example (ShopNest) In coding rounds, state complexity aloud, write a…

Coding Read answer
Mid PDF
Power of a Number (x^n) — Fast Exponentiation double Power(double x, int n) Follow on: { if (n == 0) return 1; double temp = Power(x, n / 2); if (n % 2 == 0) return temp * temp; else return (n > 0) ?

Short answer: x * temp * temp : (temp * temp) / x; Explanation: Recursive fast power divides exponent by 2 to reduce complexity to O(log n). Explain a bit more x * temp * temp : (temp * temp) / x; Explanation: Recursive…

Coding Read answer
Mid PDF
Find Majority Element (Boyer-Moore Voting Algorithm) int MajorityElement(int[] nums) { int count = 0, candidate = 0; foreach (var num in nums) { if (count == 0) candidate = num; count += (num == candidate) ?

Short answer: 1 : -1; return candidate; Explanation: Maintain a candidate and count; majority element survives this cancellation. Real-world example (ShopNest) In coding rounds, state complexity aloud, write a clear Shop…

Coding Read answer
Mid PDF
Maximum Subarray Sum (Kadane’s Algorithm)?

Short answer: int MaxSubArray(int[] nums) { int maxSoFar = nums[0]; int maxEndingHere = nums[0]; for (int i = 1; i < nums.Length; i++) { maxEndingHere = Math.Max(nums[i], maxEndingHere + nums[i]); maxSoFar = Math.Max(…

Coding Read answer
Mid PDF
Thread-safe Singleton (Best Practice)?

Short answer: public sealed class Singleton { private static readonly object lockObj = new object(); private static Singleton instance; private Singleton() { } public static Singleton Instance { get { if (instance == nul…

Coding Scenarios Read answer
Mid PDF
Maximum Sum Increasing Subsequence int MaxSumIncreasingSubsequence(int[] nums) { int n = nums.Length; int[] dp = new int[n];

Short answer: rray.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(); } rray.Copy(nums…

Coding Read answer
Mid PDF
Check if a binary tree is a valid BST (with recursion)?

Short answer: bool IsValidBST(TreeNode root) { return Validate(root, null, null); } Follow on: bool Validate(TreeNode node, int? Explain a bit more min, int? max) { if (node == null) return true; if ((min != null &&a…

Coding Read answer
Mid PDF
Find the longest substring with exactly two distinct characters?

Short answer: public int LengthOfLongestSubstringTwoDistinct(string s) { int left = 0, right = 0, maxLen = 0; Dictionary<char, int> map = new Dictionary<char, int>(); while (right < s.Length) { Follow on:…

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: (Others Appear Twice) int SingleNonDuplicate(int[] nums)

Example code

{
int low = 0, high = nums.Length - 1; while (low < high) {
int mid = low + (high - low) / 2;
if (mid % 2 == 1) mid--; // ensure mid is even
if (nums[mid] == nums[mid + 1])
low = mid + 2; else high = mid; Follow on: }
return nums[low];
} Explanation: Pairs appear consecutively; use binary search on even indices to find mismatch.

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 WordBreak(string s, HashSet<string> wordDict) { bool[] dp = new bool[s.Length + 1]; dp[0] = true; for (int i = 1; i <= s.Length; i++) { for (int j = 0; j < i; j++) { if (dp[j] && wordDict.Contains(s.Substring(j, i - j))) { dp[i] = true; break; } } } return dp[s.Length]; } Explanation: DP to check if substring can be segmented using dictionary words. Follow on:

Example code

bool WordBreak(string s, HashSet<string> wordDict) {
bool[] dp = new bool[s.Length + 1];
dp[0] = true;
for (int i = 1; i <= s.Length; i++)
{
for (int j = 0; j < i; j++)
{
if (dp[j] && wordDict.Contains(s.Substring(j, i - j)))
{
dp[i] = true; break; }
}
}
return dp[s.Length];
} Explanation: DP to check if substring can be segmented using dictionary words. 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: string input = "programming"; Dictionary<char, int> map = new Dictionary<char, int>(); foreach (char c in input) map[c] = map.ContainsKey(c) ? map[c] + 1 : 1; foreach (var item in map) { if (item.Value > 1) Console.WriteLine(item.Key); }

Example code

string input = "programming";
Dictionary<char, int> map = new Dictionary<char, int>();
foreach (char c in input)
map[c] = map.ContainsKey(c) ? map[c] + 1 : 1;
foreach (var item in map)
{
if (item.Value > 1) Console.WriteLine(item.Key); }

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 MajorityElement(int[] nums) { int count = 0, candidate = 0; foreach (var num in nums) { if (count == 0) candidate = num; count += (num == candidate) ? 1 : -1; } return candidate; } Explanation: Boyer-Moore Voting Algorithm tracks majority element by counting net votes. Follow on:

Example code

int MajorityElement(int[] nums)
{
int count = 0, candidate = 0;
foreach (var num in nums)
{
if (count == 0)
candidate = num;
count += (num == candidate) ? 1 : -1;
}
return candidate;
} Explanation: Boyer-Moore Voting Algorithm tracks majority element by counting net votes. 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: double Power(double x, int n) Follow on: {

Example code

if (n == 0) return 1;
double temp = Power(x, n / 2);
if (n % 2 == 0)
return temp * temp; else return (n > 0) ? x * temp * temp : (temp * temp) / x;
} Explanation: Recursive fast power divides exponent by 2 to reduce complexity to O(log n).

Real-world example (ShopNest)

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

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

Short answer: Algorithm) int MajorityElement(int[] nums)

Example code

{
int count = 0, candidate = 0;
foreach (var num in nums)
{
if (count == 0)
candidate = num;
count += (num == candidate) ? 1 : -1;
}
return candidate;
} Explanation: Maintain a candidate and count; majority element survives this cancellation.

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 FindDuplicate(int[] nums) { int slow = nums[0], fast = nums[0]; do { slow = nums[slow]; fast = nums[nums[fast]]; } while (slow != fast); fast = nums[0]; while (slow != fast) { slow = nums[slow]; fast = nums[fast]; } return slow; } Explanation: Floyd’s Tortoise and Hare cycle detection, treating values as pointers.

Example code

public int FindDuplicate(int[] nums) {
int slow = nums[0], fast = nums[0]; do { slow = nums[slow];
fast = nums[nums[fast]];
} while (slow != fast);
fast = nums[0]; while (slow != fast) { slow = nums[slow];
fast = nums[fast];
}
return slow;
} Explanation: Floyd’s Tortoise and Hare cycle detection, treating values as 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 MinCutPalindromePartition(string s) { int n = s.Length; bool[,] dp = new bool[n, n]; int[] cuts = new int[n]; for (int i = 0; i < n; i++) { int minCuts = i; for (int j = 0; j <= i; j++) { if (s[j] == s[i] && (i - j < 2 || dp[j + 1, i - 1])) { dp[j, i] = true; minCuts = j == 0 ? 0 : Math.Min(minCuts, cuts[j - 1] + 1); } } cuts[i] = minCuts; } return cuts[n - 1]; }

Example code

int MinCutPalindromePartition(string s) {
int n = s.Length;
bool[,] dp = new bool[n, n];
int[] cuts = new int[n];
for (int i = 0; i < n; i++) {
int minCuts = i;
for (int j = 0; j <= i; j++) {
if (s[j] == s[i] && (i - j < 2 || dp[j + 1, i - 1])) {
dp[j, i] = true; minCuts = j == 0 ? 0 : Math.Min(minCuts, cuts[j - 1] + 1); }
}
cuts[i] = minCuts;
}
return cuts[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: bool PrintAncestors(TreeNode root, int target) { if (root == null) return false; if (root.val == target) return true; if (PrintAncestors(root.left, target) || PrintAncestors(root.right, target)) { Console.Write(root.val + " "); return true; } return false; } Explanation: Recursive check if target is in subtree; print current node on path back if yes.

Example code

bool PrintAncestors(TreeNode root, int target) { if (root == null) return false;
if (root.val == target) return true;
if (PrintAncestors(root.left, target) || PrintAncestors(root.right, target)) { Console.Write(root.val + " "); return true;
}
return false;
} Explanation: Recursive check if target is in subtree; print current node on path back if yes.

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: 1 : -1; return candidate; Explanation: Boyer-Moore Voting Algorithm tracks majority element by counting net votes. Follow on:

Real-world example (ShopNest)

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

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

Short answer: x * temp * temp : (temp * temp) / x; Explanation: Recursive fast power divides exponent by 2 to reduce complexity to O(log n).

Explain a bit more

x * temp * temp : (temp * temp) / x; Explanation: Recursive fast power divides exponent by 2 to reduce complexity to O(log n). x * temp * temp : (temp * temp) / x; Explanation: Recursive fast power divides exponent by 2 to reduce complexity to O(log n). x * temp * temp : (temp * temp) / x; Explanation: Recursive fast power divides exponent by 2 to reduce complexity to O(log n).

Real-world example (ShopNest)

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

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

C# Coding Interview C# Programming Tutorial · Coding

Short answer: 1 : -1; return candidate; Explanation: Maintain a candidate and count; majority element survives this cancellation.

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 MaxSubArray(int[] nums) { int maxSoFar = nums[0]; int maxEndingHere = nums[0]; for (int i = 1; i < nums.Length; i++) { maxEndingHere = Math.Max(nums[i], maxEndingHere + nums[i]); maxSoFar = Math.Max(maxSoFar, maxEndingHere); } return maxSoFar; } Explanation: Track max subarray ending at current position; update global max.

Example code

int MaxSubArray(int[] nums)
{
int maxSoFar = nums[0];
int maxEndingHere = nums[0];
for (int i = 1; i < nums.Length; i++)
{
maxEndingHere = Math.Max(nums[i], maxEndingHere + nums[i]);
maxSoFar = Math.Max(maxSoFar, maxEndingHere);
}
return maxSoFar;
} Explanation: Track max subarray ending at current position; update global 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 Scenarios

Short answer: public sealed class Singleton { private static readonly object lockObj = new object(); private static Singleton instance; private Singleton() { } public static Singleton Instance { get { if (instance == null) { lock (lockObj) { if (instance == null) instance = new Singleton(); } } return instance; } } }

Example code

public sealed class Singleton
{
private static readonly object lockObj = new object();
private static Singleton instance;
private Singleton() { }
public static Singleton Instance
{ get {
if (instance == null)
{ lock (lockObj) {
if (instance == null)
instance = new Singleton();
}
}
return instance;
}
}
}

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.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(); } rray.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…… rray.Copy(nums, dp, n); for (int i = 1; i < n; i++) { for (int…

Explain a bit more

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(); } rray.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: bool IsValidBST(TreeNode root) { return Validate(root, null, null); } Follow on: bool Validate(TreeNode node, int?

Explain a bit more

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.

Example code

bool IsValidBST(TreeNode root) { return Validate(root, null, null);
} Follow on: bool Validate(TreeNode node, int? 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.

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 LengthOfLongestSubstringTwoDistinct(string s) { int left = 0, right = 0, maxLen = 0; Dictionary<char, int> map = new Dictionary<char, int>(); while (right < s.Length) { Follow on: char c = s[right]; map[c] = right; if (map.Count > 2) { int delIndex = map.Values.Min(); map.Remove(s[delIndex]); left = delIndex + 1; } maxLen = Math.Max(maxLen, right - left + 1); right++; } return maxLen; } Explanation:…

Explain a bit more

Sliding window with hashmap to track indices of distinct chars, remove the leftmost when >2.

Example code

public int LengthOfLongestSubstringTwoDistinct(string s) {
int left = 0, right = 0, maxLen = 0;
Dictionary<char, int> map = new Dictionary<char, int>(); while (right < s.Length) { Follow on: char c = s[right];
map[c] = right;
if (map.Count > 2) {
int delIndex = map.Values.Min(); map.Remove(s[delIndex]); left = delIndex + 1;
}
maxLen = Math.Max(maxLen, right - left + 1); right++; }
return maxLen;
} Explanation: Sliding window with hashmap to track indices of distinct chars, remove the leftmost when >2.

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