Solved by : Souryadeep Sen
Home page : My home page
All solutions : Using C/C++ programming language.
Source code : src
Headers : headers
Collaboration : I am open to collobaration. Please submit a pull request if there is a better way to solve the problem/there is a bug
I created this repo to serve as a reference for others working on leetcode problems, and am working on documenting my approach to solving the problems, which I will publish on this page.
There are always multiple ways to solve problems, as you will see on leetcode too.
I have tried to add in some other best practices such as memory management.
Disclaimer: These do not neccesarily represent the most optimum solution. I am open to collaboration, and feel free to submit a pull request if you would like to contribute to the repo.
Please see my documentation on installing gcc (compulsory) and other optional tools @ Link
Compiling the code on linux command line:
- For code with comments that mentions 'use with ...'
- gcc -g -Wall -I../include program.c otherCFiles.c -o test -l(pthread/m/..)
- for C++ code, replace the gcc with g++
- -I../include is used to tell the compiler where the header files are
- other C Files will be in the src directory
- -l() is used to tell the linker to link a particular library, such as pthread, math (m) and so on
- -g is a debug flag, -Wall is to turn on warnings
- For code without the above comment
- gcc -g -Wall program.c -o test -l(pthread/m/...)
Executing the code on linux command line:
- With valgrind
- valgrind --leak-check=yes ./test <cmdlineoptions>
- Without valgrind
- ./test <cmdlineoptions>
👷 work in progress...
| Type | Question | Difficulty | Comments |
|---|---|---|---|
| Math | 1. Pallindrome | Easy | |
| 2. Sqrt | Easy | ||
| 3. Pow | Medium | ||
| 4. PlusOne | Easy | ||
| 5. RomanToInt | Easy | ||
| 6. TwoSum | Easy | ||
| 7. Reverse Int | Medium | ||
| 8. Double Reverse Int | Easy | ||
| String | 1. LCPrefix | Easy | |
| 2. Valid Parenthesis | Easy | ||
| 3. StrStr | Easy | ||
| 4. My Atoi | Medium | ||
| 5. Longest Substr w/o rep | Medium | ||
| 6. Is Pallindrome | Easy | ||
| 7. Is Pallindrome 2 | Easy | ||
| 8. Longest Repeating Substr | Medium | Using hashtable. This is a partially working solution, as implementing the hash table in C is considerably more complex than higher level languages | |
| Array | 1. Remove Element | Easy | |
| 2. Next Permutation | Medium | ||
| 3. Find Duplicate | Medium | 1. Negative marking 2. Bit Manipulation | |
| 4. Max Area | Medium | 1. Two pointer 2. Brute Force | |
| 5. Search Insert | Easy | ||
| 6. Remove Duplicates | Easy | ||
| 7. Merge Sorted Arrays | Easy | 3 pointer approach | |
| 8. Search Range | Medium | ||
| 9. Find Missing Ranges | Easy | ||
| 10.Minimum Buying Cost | Easy | ||
| Recursion | 1. Reverse List | Easy | use list1.c and list1.h |
| 2. Merge lists | Easy | use list2.c and list2.h | |
| Bit Manipulation | 1. Add Binary | Easy | |
| 2. Reverse Bits | Easy | ||
| 3. Hamming Weight | Easy | ||
| 4. Alternating Bits | Easy | ||
| 5. Subsets | Medium | Solved using bit manipulation. | |
| 6. Missing Number | Easy | ||
| 7. Single Number | Easy | Bit manipulation solution | |
| 8. Pallindrome Permutation | Easy | ||
| 9. Sum of Two Ints | Medium | ||
| 10. Gray Code | Medium | wip | |
| 11. Power of Two | Easy | ||
| 12. Power of Four | Easy | ||
| 13. Binary Watch | Easy | ||
| Hash Table | 1. Find the Difference | Easy | |
| 2. First Unique Char | Easy | ||
| Concurrency | 1. Print in Order | Easy | |
| Dynamic Programming | 1. Count Bits | Easy | Bit manipulation also used |
| 2. Climb Stairs | Easy | Used memoization | |
| 3. Max Sub Array | Easy | ||
| 4. Buy/Sell Stock | Easy | ||
| 5. Buy/Sell Stock | Medium | ||
| 6. Pascal Triangle | Easy | ||
| 7. Is Subsequence | Easy | ||
| 8. Longest Palindrome Substr | Medium | Around the center method used | |
| Linked List | 1. Delete Duplicates | Easy | use list2.h and list2.c |
| 2. Keep Unique | Medium | use list2.h and list2.c | |
| 3. Swap Pairs | Medium | use list2.c and list2.h | |
| 4. Reverse K Group | Hard | use list2.c and list2.h | |
| 5. Remove Nth element End | Medium | use list2.c and list2.h | |
| 6. Has Cycle | Easy | use list2.c and list2.h | |
| 7. Add 2 nums | Medium | ||
| Simulation | 1. Fizz Buzz | Easy | Also a string/math Q |
| Matrix | 1. Rotate90 | Medium | |
| Interactive | 1. First Bad Version | Easy | Binary search implemented |
| 2. Guess Number | Easy | Binary search implemented | |
| Sorting | 1. Majority Element | Easy | |
| 2. Insertion Sort List | Medium | ||
| Graph | 1. Walls and Gates | Medium | |
| 2. Number of Islands | Medium | ||
| 3. Open Lock | Medium | ||
| Stack | 1. Min Stack | Easy | |
| 2. Reverse Polish | Medium | ||
| 3. Num of Islands | Medium | solved with DFS | |
| 4. BST Inorder traverse | Easy | ||
| 🔝 Go To TOP |