Skip to content
/ 73 Public

The 73 most useful LeetCode problems implemented in C, C++, C# and F#

Notifications You must be signed in to change notification settings

jonas1ara/73

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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")

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, C++ and C#, 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
    |- .vscode
        |- tasks.json
    |- Problems
        |- Arrays
        |- Matrix
            |- Rotate-Image
                |- Rotate-Image.c
                |- Rotate-Image.cpp
                |- Rotate-Image.cs
                |- Rotate-Image.csproj
                |- README.md
            |- Set-Matrix-Zeroes
            |- Spiral-Matrix
            |- Word-Search
        |- Strings
        |- Intervals
        |- Binary Search
        |- Dynamic Programming
        |- Linked Lists
        |- Trees
        |- Heaps
        |- Graphs
    |- Sources
        |- Sheldon.gif
  • .vscode: Contains the 'tasks.json' file that configures the build task in Visual Studio Code for /usr/bin/g++ and the configuration for the output generated ${fileDirname}\\${fileBasenameNoExtension}.out

  • 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 Two-Sum.c (Only in the first problem of each topic there is an implementation in C language to go a little deeper), the C++ source code Two-Sum .cpp, the C# source code in Two-Sum.cs and the .NET project settings in Two-Sum.csproj and finally the README.md file

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

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 also written in C++, only the first problem of each topic includes the solution in C and only in the last problem of each topic includes the solution in F#, so to use this repository you must have installed:

To compile C# and F# you need to install dotnet-sdk

  • dotnet-sdk-8.0

At this time the dotnet sdk is available from the Ubuntu 22.04 and Fedora 39 source, so, to install you can copy and paste the following commands:

Ubuntu 22.04 or later:

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

Fedora 39 or later:

sudo dnf install dotnet-sdk-8.0

Note: To install on other linux versions or linux distributions, please check this page.

If you want use this repository with C and C++ then you should install gcc and g++

  • gcc
  • g++

To install them on Debian based distributions you can type:

Debian based distributions:

sudo apt update && \
    sudo apt install build-essential -y

Red hat based distributions:

sudo dnf install gcc g++ -y

Index 📖

Arrays

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

Matrix

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

Strings

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

Intervals

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

Binary

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

Dynamic Programming

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

Linked Lists

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

Trees

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

Heaps

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

Graphs

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

Build with 🛠️

C# Conferences 📊

C++ Conferences 📊

References 📚

Cppreference.com. (s. f.). https://en.cppreference.com/w/

Eckel, B. (2004). Thinking in C++. Thinking in C++ (2nd ed.). Pearson.

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.

Acknowledgments 🎁

Written with ❤️ by Jonas Lara for anyone who is interested