Roadmap › 0. Fundamentals › Step 3
{}
Coding Round Practice (DSA in C#)
Big-O, arrays, strings, hashing, two pointers, sliding window, stacks, linked lists, trees, sorting, searching, recursion and the most-asked C# coding programs with solutions.
Quick revision for interview day. Print it or save it as a PDF.
Pattern → when to use
| Clue in the problem | Pattern |
|---|---|
| "pair/complement", "seen before", duplicates | Hash map / HashSet |
| Sorted array, pair sum, palindrome | Two pointers |
| Contiguous subarray/substring, "longest/shortest window" | Sliding window |
| Brackets, "next greater", undo | Stack (monotonic stack) |
| Shortest path unweighted, level order | BFS (Queue) |
| All paths, islands, tree recursion | DFS |
| Sorted + search, "minimum feasible value" | Binary search |
| Top K, k-th largest, merge k lists | Heap (PriorityQueue) |
| Overlapping subproblems, "number of ways" | DP / memoisation |
| All combinations/permutations | Backtracking |
| Linked list cycle/middle | Fast & slow pointers |
Complexity of C# collections
| Operation | List | Dictionary/HashSet | SortedDictionary | LinkedList |
|---|---|---|---|---|
| Add | O(1)* | O(1)* | O(log n) | O(1) |
| Search | O(n) | O(1) | O(log n) | O(n) |
| Remove | O(n) | O(1) | O(log n) | O(1) with node |
| Index | O(1) | — | — | O(n) |
*amortised/average
Must-know programs (practise until automatic)
Reverse string · palindrome · anagram · char count · first unique char · reverse words · Fibonacci · prime · factorial · Armstrong · FizzBuzz · swap · second largest · duplicates · missing number · move zeros · rotate array · merge sorted arrays · two sum · Kadane · valid parentheses · reverse linked list · cycle detection · binary search · bubble/quick/merge sort · tree height/BFS · LRU cache.
Useful C# snippets
csharp
counts[c] = counts.GetValueOrDefault(c) + 1;
(a, b) = (b, a);
var pq = new PriorityQueue<string, int>(); // min-heap
var maxPq = new PriorityQueue<int, int>(Comparer<int>.Create((x, y) => y.CompareTo(x)));
int mid = lo + (hi - lo) / 2;
s[^1]; s[1..^1]; arr[..k];
Array.Sort(arr); Array.Reverse(arr, i, len);
string.Join(",", list);Answer checklist
Clarify → examples → brute force + Big-O → optimise → code → dry-run → edge cases (empty, one, duplicates, negatives, overflow) → final Big-O.