Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

852 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

73 - The best number

According to Sheldon Cooper the best number is 73, because 73 is the 21st prime number. Its mirror, 37, is the 12th prime number. 21 is the product of multiplying 7 by 3 and in binary, 73 is a palindrome: 1001001

73

Sheldon Cooper (character in the famous series "The Big-Bang Theory")

Tests C# F# .NET 10 License: MIT

What is this?

This is a repository that will take you by the hand in the 73 most useful LeetCode problems, well they are actually 76, 😬 the algorithms are written in C# and F#, I wrote each program in the most optimal way and included the main function or method of the program to test on your machine, a README file with solution notes and for problems 252, 253, 269, 271 and 323 being Premium subscription problems, I included a README with the description of each problem.

No hurry, but no rest

Repository structure

The repository is divided into 4 folders:

|- Repository
    |- Problems
        |- Arrays
        |- Matrix
            |- Rotate-Image
            |- Set-Matrix-Zeroes
            |- Spiral-Matrix
            |- Word-Search
                |- Word-Search.cs
                |- Word-Search.csproj
                |- Word-Search.fsx
                |- README.md
        |- Strings
        |- Intervals
        |- Binary Search
        |- Dynamic Programming
        |- Linked Lists
        |- Trees
        |- Heaps
        |- Graphs
    |- Sources
        |- Sheldon.gif
  • Problems: Contains the folders for each topic, inside it has a folder per problem and inside each folder is the source code and the README that explains the problem, for example the Two-Sum folder contains the C# source code in Two-Sum.cs and the .NET project settings in Two-Sum.csproj (only the last problem of each topic also includes an F# solution, e.g. Word-Search.fsx) and finally the README.md file. Every problem's README.md also ends with a Suggested practice section linking 3 related LeetCode problems, so you can practice the same pattern

  • Sources: Contains the images and gifs used in the repository, such as Sheldon Cooper's gif

Index

Arrays

# Title Solution Difficulty
0001 Two Sum C# Easy
0011 Container With Most Water C# Medium
0015 3Sum C# Medium
0033 Search in Rotated Sorted Array C# Medium
0053 Maximum Subarray C# Medium
0121 Best Time to Buy and Sell Stock C# Medium
0152 Maximum Product Subarray C# Medium
0153 Find Minimum in Rotated Sorted Array C# Medium
0217 Contains Duplicate C# Easy
0238 Product of Array Except Self C# - F# Easy

Matrix

# Title Solution Difficulty
0048 Rotate Image C# Medium
0054 Spiral Matrix C# Medium
0073 Set Matrix Zeroes C# Medium
0079 Word Search C# - F# Medium

Strings

# Title Solution Difficulty
0003 Longest Substring Without Repeating Characters C# Medium
0005 Longest Palindromic Substring C# Medium
0020 Valid Parentheses C# Easy
0049 Group Anagrams C# Medium
0076 Minimum Window Substring C# Hard
0125 Valid Palindrome C# Easy
0242 Valid Anagram C# Easy
0271 Encode and Decode Strings C# Medium
0424 Longest Repeating Character Replacement C# Medium
0647 Palindromic Substrings C# - F# Medium

Intervals

# Title Solution Difficulty
0056 Merge Intervals C# Medium
0057 Insert Interval C# Medium
0252 Meeting Rooms C# Easy
0253 Meeting Rooms II C# Medium
0435 Non-overlapping Intervals C# - F# Medium

Binary

# Title Solution Difficulty
0190 Reverse Bits C# Easy
0191 Number of 1 Bits C# Easy
0268 Missing Number C# Easy
0338 Counting Bits C# Easy
0371 Sum of Two Integers C# - F# Medium

Dynamic Programming

# Title Solution Difficulty
0055 Jump Game C# Medium
0062 Unique Paths C# Medium
0070 Climbing Stairs C# Easy
0091 Decode Ways C# Medium
0139 Word Break C# Medium
0198 House Robber C# Medium
0213 House Robber II C# Medium
0300 Longest Increasing Subsequence C# Medium
0322 Coin Change C# Medium
0377 Combination Sum IV C# Medium
1143 Longest Common Subsequence C# - F# Medium

Linked Lists

# Title Solution Difficulty
0019 Remove Nth Node From End of List C# Medium
0021 Merge Two Sorted Lists C# Easy
0023 Merge k Sorted Lists C# Hard
0141 Linked List Cycle C# Easy
0143 Reorder List C# Medium
0206 Reverse Linked List C# - F# Easy

Trees

# Title Solution Difficulty
0098 Validate Binary Search Tree C# Medium
0100 Same Tree C# Easy
0102 Binary Tree Level Order Traversal C# Medium
0104 Maximum Depth of Binary Tree C# Easy
0105 Construct Binary Tree from Preorder and Inorder Traversal C# Medium
0124 Binary Tree Maximum Path Sum C# Hard
0208 Implement Trie (Prefix Tree) C# Medium
0211 Design Add and Search Words Data Structure C# Medium
0212 Word Search II C# Hard
0226 Invert Binary Tree C# Hard
0230 Kth Smallest Element in a BST C# Medium
0235 Lowest Common Ancestor of a Binary Search Tree C# Medium
0297 Serialize and Deserialize Binary Tree C# Hard
0572 Subtree of Another Tree C# - F# Easy

Heaps

# Title Solution Difficulty
0295 Find Mediumn from Data Stream C# Hard
0347 Top K Frequent Elements C# Medium
0355 Design Twitter C# - F# Medium

Graphs

# Title Solution Difficulty
0128 Longest Consecutive Sequence C# Medium
0133 Clone Graph C# Medium
0200 Number of Islands C# Medium
0207 Course Schedule C# Medium
0261 Graph Valid Tree C# Medium
0269 Alien Dictionary C# Hard
0323 Number of Connected Components in an Undirected Graph C# Medium
0417 Pacific Atlantic Water Flow C# - F# Medium

Configuration

The focus of this repository is towards C#, so you can use it from Windows, Linux, Mac, Docker or even GitHub Codespaces, but it is intended to be used on Linux, specifically an Ubuntu based distribution or Red Hat based distribution, no matter if it is a complete distro or a WSL distro. All solutions are written in C#, and only the last problem of each topic also includes a solution in F#.

Prerequisites

  • dotnet-sdk-10.0 — required to build and run both the C# and F# solutions.

Ubuntu 22.04 or later:

sudo apt update && \
    sudo apt install -y dotnet-sdk-10.0

Fedora 39 or later:

sudo dnf install -y dotnet-sdk-10.0

Note: To install on other Linux versions or distributions, Windows or macOS, please check this page.

Docker: run everything inside the official SDK image, mounting the repository as a volume:

docker run --rm -it -v "${PWD}:/repo" -w /repo mcr.microsoft.com/dotnet/sdk:10.0 bash

GitHub Codespaces: open the repository in a Codespace, the container image ships with dotnet-sdk-10.0 already installed, so you can build and test right away with no extra setup.

Getting started

  1. Clone the repository:
    git clone https://github.com/jonas1ara/73.git
    cd 73
  2. Restore dependencies:
    dotnet restore 73.sln
  3. Verify your SDK version:
    dotnet --version

Visual Studio

If you are on Windows and use this repository with Visual Studio, you just have to change the solution to compile: open 73.sln, pick the desired project in the Solution Explorer and set it as the startup project (or select it from the run configuration dropdown) to build and run it.

Tests

Every problem has a matching <Problem>.Tests xUnit project, all registered in 73.sln, and they also run automatically on every push/PR to main via the Tests GitHub Actions workflow.

Run the full suite (all problems)

dotnet test 73.sln

Run only one problem's tests

dotnet test Problems/<Topic>/<Problem>.Tests/<Problem>.Tests.csproj

For example:

dotnet test Problems/Graphs/Course-Schedule.Tests/Course-Schedule.Tests.csproj

Run a single test by name

dotnet test 73.sln --filter "FullyQualifiedName~CanFinish_DetectsWhetherAllCoursesCanBeCompleted"

Run with code coverage

dotnet test 73.sln --collect:"XPlat Code Coverage"

Run from Visual Studio

  1. Open 73.sln.
  2. Go to TestTest Explorer (or press Ctrl+E, T).
  3. Click Run All Tests to run the whole solution, or right-click a specific test/project in Test Explorer and choose Run to run just that one.

Build with

C# Conferences

References

F# Docs - Get started, Tutorials, reference. https://fsharp.org/docs/

C# Docs - Get started, Tutorials, reference. https://learn.microsoft.com/en-us/dotnet/csharp/

Cormen, T. H., Leiserson, C. E., Rivest, R. L. & Stein, C. (2009). Introduction to Algorithms (3rd ed.). MIT Press.

License

This project is licensed under the MIT License.

Acknowledgments

Written with ❤️ since December 2022 by Jonas Lara for anyone who is interested — started in a time without AI, improved in the age of AI.

Used by

Contributors

Languages