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 676–700 of 3281

Career & HR topics

By tech stack

Popular tracks

Mid PDF
Solve the "Find the Celebrity" problem?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Coding Read answer
Mid PDF
Find Number of Islands in 2D Matrix?

Short answer: grid[i][j] = '0'; // Mark visited DFS(grid, i + 1, j); DFS(grid, i - 1, j); DFS(grid, i, j + 1); DFS(grid, i, j - 1); } Explanation: Use DFS to mark all connected land cells, count islands by visiting unvis…

Coding Read answer
Mid PDF
Sum of Digits of a Number?

Short answer: int SumOfDigits(int n) { int sum = 0; n = Math.Abs(n); while (n > 0) { sum += n % 10; n /= 10; } return sum; } Explanation: Extract digits using modulo 10 and add. Example code int SumOfDigits(int n) { i…

Coding Read answer
Mid PDF
Binary Search?

Short answer: Follow on: int BinarySearch(int[] arr, int target) Example code { int low = 0, high = arr.Length - 1; while (low <= high) { int mid = low + (high - low) / 2; if (arr[mid] == target) return mid; else if (…

Coding Read answer
Mid PDF
Coin Change Problem (Minimum Coins to Make?

Short answer: Amount) int CoinChange(int[] coins, int amount) Example code { int[] dp = new int[amount + 1]; Array.Fill(dp, amount + 1); dp[0] = 0; for (int i = 1; i <= amount; i++) { foreach (int coin in coins) { if…

Coding Read answer
Mid PDF
Count occurrence of each word?

Short answer: string sentence = "dotnet is great dotnet is powerful"; string[] words = sentence.Split(' '); Dictionary<string, int> map = new Dictionary<string, int>(); foreach (string word in words…

Coding Scenarios Read answer
Mid PDF
Reverse the bits of a number?

Short answer: public uint ReverseBits(uint n) { uint result = 0; for (int i = 0; i < 32; i++) { result <<= 1; result |= (n & 1); n >>= 1; } return result; } Explanation: Iteratively take least signific…

Coding Read answer
Mid PDF
Implement a trie (prefix tree) for string matching?

Short answer: public class TrieNode { public TrieNode[] Children = new TrieNode[26]; public bool IsEnd = false; } public class Trie { private TrieNode root; public Trie() { root = new TrieNode(); } public void Insert(str…

Coding Read answer
Mid PDF
Find number of trailing zeroes in factorial of a number?

Short answer: public int TrailingZeroes(int n) { int count = 0; while (n > 0) { n /= 5; count += n; } return count; } Explanation: Count factors of 5 in factorial since 2s are plentiful, trailing zeros depend on 5s. E…

Coding Read answer
Mid PDF
Search for a range (find start and end indices of target in sorted array)?

Short answer: public int[] SearchRange(int[] nums, int target) { int left = FindBoundary(nums, target, true); int right = FindBoundary(nums, target, false); return new int[] { left, right }; } private int FindBoundary(in…

Coding Read answer
Mid PDF
Edit Distance (Levenshtein Distance)?

Short answer: int EditDistance(string word1, string word2) { int m = word1.Length, n = word2.Length; int[,] dp = new int[m + 1, n + 1]; for (int i = 0; i <= m; i++) dp[i, 0] = i; for (int j = 0; j <= n; j++) dp[0,…

Coding Read answer
Mid PDF
Print nodes at a specific level (BFS)?

Short answer: void PrintNodesAtLevel(Dictionary<int, List<int>> graph, int start, int targetLevel) { Example code var visited = new HashSet<int>(); var queue = new Queue<(int node, int level)>();…

Coding Read answer
Mid PDF
Level-order traversal but return values in reverse order?

Short answer: List<List<int>> LevelOrderBottom(TreeNode root) { Example code var res = new List<List<int>>(); if (root == null) return res; Queue<TreeNode> queue = new Queue<TreeNode>(…

Coding Read answer
Mid PDF
Flatten a linked list with next and child pointers?

Short answer: public class MultiLevelNode { public int val; public MultiLevelNode next; public MultiLevelNode child; public MultiLevelNode(int x) { val = x; next = null; child = null; } } MultiLevelNode Flatten(MultiLeve…

Coding Read answer
Mid PDF
Find the Smallest Window in String s that Contains?

Short answer: All Characters of String t string MinWindow(string s, string t) return minLen == int.MaxValue ? "" : s.Substring(minLeft, minLen); } Explanation: Sliding window with two pointers keeps track of co…

Coding Read answer
Mid PDF
Find Longest Consecutive Sequence in an Unsorted?

Short answer: Array int LongestConsecutive(int[] nums) Example code { HashSet<int> set = new HashSet<int>(nums); int longest = 0; foreach (int num in set) { if (!set.Contains(num - 1)) Follow on: { int curren…

Coding Read answer
Mid PDF
Count Trailing Zeroes in Factorial of a Number?

Short answer: int TrailingZeroes(int n) { int count = 0; for (int i = 5; i <= n; i *= 5) { count += n / i; } return count; } Explanation: Trailing zeros come from factors of 10 = 2 × 5, but 2s are plenty, count 5s. Ex…

Coding Read answer

C# Coding Interview C# Programming Tutorial · Coding

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

Example code

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

Real-world example (ShopNest)

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

Say this in the interview

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

C# Coding Interview C# Programming Tutorial · Coding

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

Example code

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

Real-world example (ShopNest)

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

Say this in the interview

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: appears twice except one public int SingleNumber(int[] nums) {

Example code

int result = 0;
foreach (var num in nums) {
result ^= num;
}
return result;
} Explanation: XOR of all elements cancels duplicates, leaving the single unique element.

Real-world example (ShopNest)

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

Say this in the interview

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

C# Coding Interview C# Programming Tutorial · Coding

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

Example code

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

Real-world example (ShopNest)

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

Say this in the interview

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

C# Coding Interview C# Programming Tutorial · Coding

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

Explain a bit more

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

Example code

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

Real-world example (ShopNest)

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

Say this in the interview

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

C# Coding Interview C# Programming Tutorial · Coding

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

Explain a bit more

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

Example code

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

Real-world example (ShopNest)

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

Say this in the interview

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

C# Coding Interview C# Programming Tutorial · Coding

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

Example code

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

Real-world example (ShopNest)

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

Say this in the interview

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

C# Coding Interview C# Programming Tutorial · Coding

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

Explain a bit more

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

Real-world example (ShopNest)

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

Say this in the interview

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

C# Coding Interview C# Programming Tutorial · Coding

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

Example code

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

Real-world example (ShopNest)

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

Say this in the interview

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: grid[i][j] = '0'; // Mark visited DFS(grid, i + 1, j); DFS(grid, i - 1, j); DFS(grid, i, j + 1); DFS(grid, i, j - 1); } Explanation: Use DFS to mark all connected land cells, count islands by visiting unvisited lands.

Example code

int NumIslands(char[][] grid)
{
if (grid == null || grid.Length == 0) return 0;
int count = 0;
for (int i = 0; i < grid.Length; i++)
{
for (int j = 0; j < grid[0].Length; j++)
{
if (grid[i][j] == '1') Follow on: { DFS(grid, i, j); count++; }
}
}
return count;
} void DFS(char[][] grid, int i, int j) {
if (i < 0 || j < 0 || i >= grid.Length || j >= grid[0].Length || grid[i][j] == '0') 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: int SumOfDigits(int n) { int sum = 0; n = Math.Abs(n); while (n > 0) { sum += n % 10; n /= 10; } return sum; } Explanation: Extract digits using modulo 10 and add.

Example code

int SumOfDigits(int n)
{
int sum = 0;
n = Math.Abs(n); while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
} Explanation: Extract digits using modulo 10 and add.

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: int BinarySearch(int[] arr, int target)

Example code

{
int low = 0, high = arr.Length - 1; while (low <= high) {
int mid = low + (high - low) / 2;
if (arr[mid] == target)
return mid; else if (arr[mid] < target) low = mid + 1; else high = mid - 1;
}
return -1;
} Explanation: Standard binary search to find target’s index or -1 if not found.

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: Amount) int CoinChange(int[] coins, int amount)

Example code

{
int[] dp = new int[amount + 1]; Array.Fill(dp, amount + 1); dp[0] = 0;
for (int i = 1; i <= amount; i++)
{
foreach (int coin in coins)
{
if (coin <= i)
dp[i] = Math.Min(dp[i], 1 + dp[i - coin]);
}
}
return dp[amount] > amount ? -1 : dp[amount];
} Explanation: Bottom-up DP: min coins needed for all amounts up to target. 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 sentence = "dotnet is great dotnet is powerful"; string[] words = sentence.Split(' '); Dictionary<string, int> map = new Dictionary<string, int>(); foreach (string word in words) map[word] = map.ContainsKey(word) ? map[word] + 1 : 1;

Example code

string sentence = "dotnet is great dotnet is powerful";
string[] words = sentence.Split(' ');
Dictionary<string, int> map = new Dictionary<string, int>();
foreach (string word in words)
map[word] = map.ContainsKey(word) ? map[word] + 1 : 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: public uint ReverseBits(uint n) { uint result = 0; for (int i = 0; i < 32; i++) { result <<= 1; result |= (n & 1); n >>= 1; } return result; } Explanation: Iteratively take least significant bit of n, add it to result’s LSB, shift both accordingly. Follow on: Follow on:

Example code

public uint ReverseBits(uint n) {
uint result = 0;
for (int i = 0; i < 32; i++) {
result <<= 1;
result |= (n & 1);
n >>= 1;
}
return result;
} Explanation: Iteratively take least significant bit of n, add it to result’s LSB, shift both accordingly. Follow on: 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 class TrieNode { public TrieNode[] Children = new TrieNode[26]; public bool IsEnd = false; } public class Trie { private TrieNode root; public Trie() { root = new TrieNode(); } public void Insert(string word) { TrieNode node = root; foreach (char c in word) { int idx = c - 'a'; if (node.Children[idx] == null) node.Children[idx] = new TrieNode(); node = node.Children[idx]; } node.IsEnd = true; } public bool…

Explain a bit more

Search(string word) { TrieNode node = SearchNode(word); return node != null && node.IsEnd; } public bool StartsWith(string prefix) { return SearchNode(prefix) != null; } private TrieNode SearchNode(string word) { TrieNode node = root; foreach (char c in word) { int idx = c - 'a'; if (node.Children[idx] == null) return null; Follow on: node = node.Children[idx]; } return node; } } Explanation: Standard trie with insert, search, and prefix checking.

Example code

public class TrieNode {
public TrieNode[] Children = new TrieNode[26];
public bool IsEnd = false;
}
public class Trie {
private TrieNode root;
public Trie() {
root = new TrieNode();
}
public void Insert(string word) {
TrieNode node = root;
foreach (char c in word) {
int idx = c - 'a';
if (node.Children[idx] == null)
node.Children[idx] = new TrieNode();
node = node.Children[idx];
}
node.IsEnd = true;
}
public bool Search(string word) {
TrieNode node = SearchNode(word);
return node != null && node.IsEnd;
}
public bool StartsWith(string prefix) {
return SearchNode(prefix) != null;
}
private TrieNode SearchNode(string word) {
TrieNode node = root;
foreach (char c in word) {
int idx = c - 'a';
if (node.Children[idx] == null) return null; Follow on: node = node.Children[idx];
}
return node;
}
} Explanation: Standard trie with insert, search, and prefix checking.

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 TrailingZeroes(int n) { int count = 0; while (n > 0) { n /= 5; count += n; } return count; } Explanation: Count factors of 5 in factorial since 2s are plentiful, trailing zeros depend on 5s.

Example code

public int TrailingZeroes(int n) {
int count = 0; while (n > 0) { n /= 5;
count += n;
}
return count;
} Explanation: Count factors of 5 in factorial since 2s are plentiful, trailing zeros depend on 5s.

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[] SearchRange(int[] nums, int target) { int left = FindBoundary(nums, target, true); int right = FindBoundary(nums, target, false); return new int[] { left, right }; } private int FindBoundary(int[] nums, int target, bool findFirst) { Follow on: int left = 0, right = nums.Length - 1; int boundary = -1; while (left <= right) { int mid = left + (right - left) / 2; if (nums[mid] == target) { boundary = mid;…

Explain a bit more

if (findFirst) right = mid - 1; else left = mid + 1; } else if (nums[mid] < target) left = mid + 1; else right = mid - 1; } return boundary; } Explanation: Binary search twice — once to find first occurrence and once for last occurrence.

Example code

public int[] SearchRange(int[] nums, int target) {
int left = FindBoundary(nums, target, true);
int right = FindBoundary(nums, target, false);
return new int[] { left, right };
}
private int FindBoundary(int[] nums, int target, bool findFirst) { Follow on: int left = 0, right = nums.Length - 1;
int boundary = -1; while (left <= right) { int mid = left + (right - left) / 2;
if (nums[mid] == target) {
boundary = mid;
if (findFirst)
right = mid - 1; else left = mid + 1;
}
else if (nums[mid] < target) left = mid + 1;
else right = mid - 1;
}
return boundary;
} Explanation: Binary search twice — once to find first occurrence and once for last 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 EditDistance(string word1, string word2) { int m = word1.Length, n = word2.Length; int[,] dp = new int[m + 1, n + 1]; for (int i = 0; i <= m; i++) dp[i, 0] = i; for (int j = 0; j <= n; j++) dp[0, j] = j; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (word1[i - 1] == word2[j - 1]) dp[i, j] = dp[i - 1, j - 1]; else Follow on: dp[i, j] = 1 + Math.Min(dp[i - 1, j - 1], Math.Min(dp[i - 1, j], dp[i,…

Example code

int EditDistance(string word1, string word2) {
int m = word1.Length, n = word2.Length;
int[,] dp = new int[m + 1, n + 1];
for (int i = 0; i <= m; i++) dp[i, 0] = i;
for (int j = 0; j <= n; j++) dp[0, j] = j;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (word1[i - 1] == word2[j - 1])
dp[i, j] = dp[i - 1, j - 1]; else Follow on: dp[i, j] = 1 + Math.Min(dp[i - 1, j - 1], Math.Min(dp[i - 1, j], dp[i, j - 1])); }
}
return dp[m, 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: void PrintNodesAtLevel(Dictionary<int, List<int>> graph, int start, int targetLevel) {

Example code

var visited = new HashSet<int>();
var queue = new Queue<(int node, int level)>(); Follow on: queue.Enqueue((start, 0)); visited.Add(start); while (queue.Count > 0) { var (node, level) = queue.Dequeue();
if (level == targetLevel) { Console.WriteLine(node); }
if (level > targetLevel) break;
foreach (var neighbor in graph[node]) {
if (!visited.Contains(neighbor)) { visited.Add(neighbor); queue.Enqueue((neighbor, level + 1)); }
}
}
} Explanation: BFS traversal with level tracking; print nodes at the requested 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: List<List<int>> LevelOrderBottom(TreeNode root) {

Example code

var res = new List<List<int>>();
if (root == null) return res;
Queue<TreeNode> queue = new Queue<TreeNode>(); queue.Enqueue(root); while (queue.Count > 0) { int size = queue.Count;
var level = new List<int>(); Follow on: for (int i = 0; i < size; i++) {
TreeNode node = queue.Dequeue(); level.Add(node.val); if (node.left != null) queue.Enqueue(node.left);
if (node.right != null) queue.Enqueue(node.right);
} res.Insert(0, level); // prepend to get reverse order }
return res;
} Explanation: Perform normal BFS, insert each level at front of result list for reversed order.

Real-world example (ShopNest)

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

Say this in the interview

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: public class MultiLevelNode { public int val; public MultiLevelNode next; public MultiLevelNode child; public MultiLevelNode(int x) { val = x; next = null; child = null; } } MultiLevelNode Flatten(MultiLevelNode head) { if (head == null) return null; MultiLevelNode dummy = new MultiLevelNode(0); MultiLevelNode prev = dummy; Stack<MultiLevelNode> stack = new Stack<MultiLevelNode>(); stack.Push(head); while…

Explain a bit more

(stack.Count > 0) { var curr = stack.Pop(); prev.next = curr; curr.child = null; // remove child pointer after flattening prev = curr; if (curr.next != null) stack.Push(curr.next); if (curr.child != null) stack.Push(curr.child); } return dummy.next; } Follow on: Explanation: Use a stack to perform DFS; attach nodes and remove child pointers.

Example code

public class MultiLevelNode {
public int val;
public MultiLevelNode next;
public MultiLevelNode child;
public MultiLevelNode(int x) { val = x; next = null; child = null; } } MultiLevelNode Flatten(MultiLevelNode head) { if (head == null) return null;
MultiLevelNode dummy = new MultiLevelNode(0);
MultiLevelNode prev = dummy;
Stack<MultiLevelNode> stack = new Stack<MultiLevelNode>(); stack.Push(head); while (stack.Count > 0) { var curr = stack.Pop();
prev.next = curr;
curr.child = null; // remove child pointer after flattening
prev = curr;
if (curr.next != null) stack.Push(curr.next);
if (curr.child != null) stack.Push(curr.child);
}
return dummy.next;
} Follow on: Explanation: Use a stack to perform DFS; attach nodes and remove child 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: All Characters of String t string MinWindow(string s, string t) return minLen == int.MaxValue ? "" : s.Substring(minLeft, minLen); } Explanation: Sliding window with two pointers keeps track of counts of chars matching the target.

Example code

{
if (string.IsNullOrEmpty(s) || string.IsNullOrEmpty(t)) return ""; Dictionary<char, int> dictT = new Dictionary<char, int>();
foreach (char c in t)
dictT[c] = dictT.ContainsKey(c) ? dictT[c] + 1 : 1;
int required = dictT.Count;
int formed = 0;
Dictionary<char, int> windowCounts = new Dictionary<char,
int>();
int left = 0, right = 0;
int minLen = int.MaxValue, minLeft = 0; while (right < s.Length) {
char c = s[right]; windowCounts[c] = windowCounts.ContainsKey(c) ? windowCounts[c] + 1 : 1; if (dictT.ContainsKey(c) && windowCounts[c] == dictT[c])
formed++; while (left <= right && formed == required) {
if (right - left + 1 < minLen)
{
minLen = right - left + 1; Follow on: minLeft = left;
}
char leftChar = s[left]; windowCounts[leftChar]--; if (dictT.ContainsKey(leftChar) && windowCounts[leftChar] < dictT[leftChar]) formed--; left++; } right++; }

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: Array int LongestConsecutive(int[] nums)

Example code

{
HashSet<int> set = new HashSet<int>(nums);
int longest = 0;
foreach (int num in set)
{
if (!set.Contains(num - 1)) Follow on: {
int currentNum = num;
int length = 1; while (set.Contains(currentNum + 1)) { currentNum++; length++; }
longest = Math.Max(longest, length);
}
}
return longest;
} Explanation: Check only starts of sequences, count consecutive numbers using HashSet for O(n).

Real-world example (ShopNest)

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

Say this in the interview

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

C# Coding Interview C# Programming Tutorial · Coding

Short answer: int TrailingZeroes(int n) { int count = 0; for (int i = 5; i <= n; i *= 5) { count += n / i; } return count; } Explanation: Trailing zeros come from factors of 10 = 2 × 5, but 2s are plenty, count 5s.

Example code

int TrailingZeroes(int n)
{
int count = 0;
for (int i = 5; i <= n; i *= 5)
{
count += n / i;
}
return count;
} Explanation: Trailing zeros come from factors of 10 = 2 × 5, but 2s are plenty, count 5s.

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