C# – Remove a set of characters from a string

The fastest and simplest way to remove a set of characters from a string is to use StringBuilder + List<char>, like this: I compared this with three other approaches. I did 100,000 iterations with a string with 2500 characters and a list of 15 characters to remove. This StringBuilder approach is almost 2x faster than … Read more

Algorithm Explained: Determine if two strings have a substring in common

Problem statement: Given two strings, determine if they have a substring in common. Example: Do “hello world” and “world” have a substring in common? Yes, they both have the substring “world”. Approach What are all the substrings of string? The string “word” is four characters long. It contains 10 substrings between length 1 and 4. … Read more

Solving whiteboard problems to prepare for coding interviews

Companies like to ask you to solve whiteboard problems during coding interviews. If it’s an in-person interview, they’ll ask you to solve the problem on a physical whiteboard. If it’s a remote interview, they’ll either have you solve the problem on a website like HackerRank, or they’ll ask you the question in a “digital whiteboard” … Read more

Multithreaded quicksort in C#

One day I decided to challenge myself by trying to implement multithreaded quicksort. I wanted to see how it would compare to the built-in sort function – Array.Sort(). I came up with two algorithms that were 2-4x faster than Array.Sort(): Top-down: divide-fork-sort-merge Bottom-up: quicksort with fork-on-recursion After continuing to tinker, in attempts to further optimize, … Read more