/csharp-coding-challenges

A few coding challenges I practice in C# to improve my skills with algorithms and data structures

Primary LanguageC#

C# Coding Challenges

Getting Started

  • Install NUnit via Nuget Package Console
  • Run the tests in the test runner

Challenges

Strings (StringUtils.cs)
  1. FindDuplicate - Find all duplicate characters in a given string
  2. DetectAnagram - Find if the two input strings are anagrams
  3. FindFirstNonRepeatingCharacter - Finds first non-repeating character in a given string
  4. ReverseStringIteratively - Reverse a string using iterations
  5. ReverseStringRecursively - Reverse a string using recursion
  6. ContainsOnlyDigits - Checks if given string only contains digits
  7. ContainsOnlyDigitsUsingRegex - Checks if given string only contains digits using Regular Expressions
  8. CountVowels - Count vowels in given string
  9. CountConstants - Count constants in a given string
  10. FindPermutations - Find all permutations of a given string (includes duplicates)
  11. CheckRotation - Check if two strings are rotation of each other
  12. IsPalindrome - Check if given string is palindrome
Binary Search Tree (BST) (BinarySearchTree.cs)
  1. Add - Adds a node
  2. Validate - Check if tree is valid
  3. Remove - Remove a node
TreeNode (TreeNode.cs)
  1. PreOrder - PreOrder Traversal Algorithm (node-left-right) - ideal for printing hierarchy
  2. InOrder - InOrder Traversal Algorithm (left-node-right) - ideal for printing sequence for BST
  3. PostOrder - PostOrder Traversal Algorithm (left-right-node) - ideal for performing tree-based operations
  4. PreOrderWithoutRecursion - PreOrder Traversal Algorithm w/o recursion
  5. InOrderWithoutRecursion - InOrder Traversal Algorithm w/o recursion
  6. PostOrderWithoutRecursion - PostOrder Traversal Algorithm w/o recursion
  7. CountLeafNodes - Count all leaf nodes using recursion
  8. CountLeafNodesWithoutRecursion - Count all leaf nodes w/o recursion
Sorting (Sorting.cs) - with time complexity
  1. BubbleSort - Average & Worst: O(n2) and Best: O(n)
  2. QuickSort - Average & Best: O(n log n) and Worst: O(n2)
  3. InsertionSort - Average & Worst: O(n2) and Best: O(n)
  4. MergeSort - O(n log n)
Miscellaneous (Miscellaneous.cs)
  1. FindUsingBinarySearch - Find array index of element using binary search
  2. CalculateFibonacciRecursively - Calculate Fibonacci using recursion
  3. CalculateFibonacciDynamically - Calculate Fibonacci using a cache
  4. CalculateFibonacciIteratively - Calculate Fibonacci using iterations
Heap (Heap.cs)
  1. MinHeap - Priority queue based on min heap (Add, Remove, GetMin)
  2. MinHeapArray - Min heap implmented as an array (Add, Remove, GetMin)
Dynamic Programming
  1. KnapsackProblem.cs - Bottom up approach by building cache before converging to a solution