/cs-algorithms

CS Algorithms practice repo.

Primary LanguageTypeScript

Algorithms

This repository provides code snippets for several of the programming questions. The questions have been read from various sources. Wherever possible, there would be links presented along with question.

Programming Langugages

I use mostly Javascript, Typescript, Java, and Scala. You can expect solutions in one of these programming languages.

Sources

The problems for the documented solutions have been fetched from various sources including Udemy, AlgoExpert, LeetCode, Educative, etc. Wherever possible, I am attaching the source. I am not attaching the sources for premium subscriptions, just to make sure the premium subscriptions are not misused.

Contributions

Happy to accept any contributions to this in any langugage.

Easy

  1. Find Numbers with Even Numbers of Digits | Solution
  2. Roman To Integer | Solution
  3. Excel Sheet Column Title | Solution
  4. Second Highest Salary | Solution
  5. Valid Phone Numbers | Solution
  6. Count Primes | Solution 1 | Solution 2
  7. Sorted Array Merge | Solution
  8. Educative Array | Solution
  9. Find Pair Sum | Solution
  10. Third Maximum Number | Solution 1 | Solution 2 | Solution 3
  11. Median of 2 sorted arrays | Solution
  12. K-Diff Pairs in an array | Solution
  13. Shortest Sorted Continuous Subarray | Solution 1 | Solution 2 | Solution 3 | Solution 4 | Solution 5 | Solution 6 | Solution 7
  14. Non Decreasing Array | Solution 1 | Solution 2 | Solution 3
  15. Buddy Strings | Solution 1 | Solution 2
  16. Rearrange Positive Negative | Solution
  17. Rearrange Sorted Max Min | Solution
  18. String Duplicates | Solution
  19. String Reversal | Solution
  20. Valid Paranthesis | Solution 1

Medium

  1. Minimum Remove to Make Valid Paranthesis | Solution
  2. Finding if the string with curly braces are balanced | Solution
  3. Create a minimum height BST using a sorted input array | Solution
  4. Find Longest Peak in an array | Solution
  5. Monotonic Increasing | Solution 1 | Solution 2
  6. Suffix Trie Construction | Solution
  7. Traversing a 2D Array in a Spiral Order: Returning 1D Array | Solution
  8. Finding groups of anagrams in a string | Solution 1 | Solution 2
  9. Finding Longest Palindromic Substring | Solution 1 BF | Solution 2
  10. Min Max Stack | Solution
  11. Leet Code 146 - LRU Cache | Solution Java Collection | Solution Typescript Custom
  12. Leet Code 283 Move Zeros | Solution | Solution 2
  13. Leet Code 70 Climbing Stairs | Solution DP Top Down | Solution DP Bottoms Up
  14. Leet Code 200 Number of Islands | Solution 1 DFS | Solution BFS | Solution Union Find
  15. Leet Code 362 Design Hit Counter | Solution 1 | Solution 2
  16. LeetCode Web Crawler 1242 | Solution 1 | Solution 2
  17. Leet Code 554 Brick Wall | Solution 1
  18. Leet Code 1190 Reverse Substrings Between Each Pair of Paranthesis | Solution 1 | Solution Optimized
  19. Leet Code 22 Generate Paranthesis | Solution Brute Force | Solution BF Optimized
  20. Leet Code 54 Spiral Matrix | Solution
  21. Leet Code 1239 - Maximum length of the unique character string | Solution
  22. Leet Code 445 - Add Numbers II | Solution 1 | Solution 2
  23. Leet Code 59 - Spiral Matrix II | Solution
  24. Leet Code 151 - Reverse Words in a String | Solution
  25. Leet Code 1647 - Minimum Deletions to Make Character Frequency Unique | Solution
  26. Microsoft OA - Max Sum of Numbers with Equal Sum Digits | Solution
  27. Microsoft OA - Min Moves to Make String without 3 Identical Chars | Solution
  28. Android Unlock Patterns | Solution 1 | Solution 2
  29. Leet Code 1573 - Number of Ways to Split a String | Solution 1 | Solution
  30. Leet Code 322: Coin Change | Solution | Sol 2 | Sol 3
  31. Leet Code 927 - 3 Equal Parts | Solution 1 | Solution 1
  32. Leet Code 103 - Tree Zig Zag | Solution | Solution | Solution
  33. Leet Code 33 - Search in rotated | Solution 1 | Solution 2
  34. Leet Code 1578 - Minimum Deletion Cost to Avoid Repeating Letters | Solution
  35. Leet Code 1576 - Replace All ?s | Solution

Hard

  1. Find Missing Positive | Solution
  2. Read N Characters Given Read 4 II - Call Multiple Times - LeetCode 158 | Solution 1 | Solution 2 Optimized
  3. Leet Code 297 - Serialize Deserialize Binary Tree | Solution
  4. Leet Code 428 - Serialize Deserialize N-Ary Tree | Solution
  5. Leet Code 25 - Reverse Linked List k Nodes at a time | Solution

Sorting

  1. Bubble Sort | Solution
  2. Insertion Sort | Solution
  3. Merge Sort | Solution
  4. Quick Sort | Solution
  5. Radix Sort | Solution
  6. Selection Sort | Solution

Frequency Pattern

  1. Anagram Check | Solution
  2. Are Same with Squares? | Solution
  3. Check Substring | Solution
  4. Count Characters in String | Solution
  5. Same Frequency | Solution

Multiple Pointers Pattern

  1. Are there Duplicates? | Solution
  2. Average Pair | Solution
  3. Count Unique Values | Solution
  4. Zero Sum Pair | Solution

Recursive Pattern

  1. Capitalize Words | Solution
  2. Collect Strings | Solution
  3. Fibonnaci | Solution Bottoms Up | Solution Dynamic Programming | Solution Recursion | Solution Recursive
  4. Factorial | Solution
  5. Flatten | Solution
  6. Is Palindrome? | Solution
  7. Nested Even Sum | Solution
  8. Power | Solution
  9. Product of Arrays | Solution
  10. Range | Solution
  11. Some Recursive | Solution
  12. Stringify Numbers | Solution

Sliding Window Pattern

  1. Finding Longest Substring | Solution
  2. Max Subarray Sum | Solution
  3. Min Subarray Length | Solution

Linked List

  1. Detecting Loops in Linked List | Solution
  2. Find Middle Node in Linked List | Solution
  3. Find nth node from last | Solution
  4. Reverse Linked List | Solution

Searching

  1. Linear Search | Solution
  2. Binary Search | Solution
  3. Searching in a Sorted Array | Solution 1 | Solution 2

Dynamic Programming

  1. 0/1 Knapsack Problem
  2. Equal Subset Problem
  3. Subset Sum Problem
  4. Minimum Difference Subset Sum
  5. Count of Subset Sum
  6. Target Sum using positive negative assignments
  7. Unbounded Knapsack Problem
  8. Road Cutting
  9. Coin Change
  10. Minimum Coin Change Needed
  11. Maximum Ribbon Cut
  12. Find Longest Palindromic Subsequence
  13. Find Longest Palindromic Substring
  1. Count Total Palindromes
    1. Solution Brute Force
    2. Solution Recursion Brute Force
    3. Solution Top Down DP
    4. Solution Bottoms Up DP
  2. Minimum Deletions Required to make a Palindrome
    1. Solution Brute Force
    2. Solution DP Bottoms Up
    3. Solution DP Top Down

TODO Items (More topics to explore further)