This is my C-language "book of code" for competitive programming problems. Thanks to the depth and breadth of competitive programming problems, this repository has become home to a diverse library including mathematical functions, data structures, and algorithms.
C is a wonderful language because powerful abstractions come at an extremely low cost. I can take liberties with my implementations (such as runtime generics) while outperforming modern (bloated) alternatives, often by orders of magnitude. Plus C is readable, elegant, and beautiful (sometimes).
- Adhere to the project style guide.
- Implement all final solutions following the C99 standard.
- Assume that the English letter characters are ordered sequentially (i.e., no EBCDIC).
- Assume that signed integer overflow is defined based on two's complement.
This repository depends on the GNU Multiple Precision Arithmetic Library
(GMP),
which is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0
).
Id | Problem | Domain | Result | Implementation |
---|---|---|---|---|
7 | Reverse Integer | Mathematics | Integer | math_reverse |
8 | String to Integer | Strings | Integer | atoll |
9 | Palindrome Number | Mathematics | Boolean | math_is_palindrome |
12 | Integer to Roman | String | Mathematics | roman_to_string_builder |
13 | Roman to Integer | Mathematics | Integer | roman_from_string_builder |
23 | Merge k Sorted Lists | Linked Lists | Linked List | PriorityQueue |
28 | Find the Index of the First Occurrence in a String | Strings | Index | strstr |
29 | Divide Two Integers | Mathematics | Quotient | |
31 | Next Permutation | Array | Permutation | PermutationIterator |
46 | Permutations | Array | Permutation | PermutationIterator |
50 | Pow(x, n) | Mathematics | Power | pow |
60 | Permutation Sequence | Mathematics | Permutation | PermutationIterator |
62 | Unique Paths | Combinatorics | Binomial coefficient | binomial |
69 | Sqrt(x) | Mathematics | Square root | sqrt |
75 | Sort Colors | Sorting | Sort | qsort |
77 | Combinations | Backtracking | Matrix | CombinationIterator |
150 | Evaluate Reverse Polish Notation | Mathematics | Integer | rpn_evaluate |
202 | Happy Number | Mathematics | Boolean | SquareDigitChain |
204 | Count Primes | Mathematics | Count | Sieve , binary_search_rank |
258 | Add Digits | Mathematics | Digital root | |
263 | Ugly Number | Mathematics | Boolean | |
273 | Integer to English Words | Mathematics | String | words_to_string |
367 | Valid Perfect Square | Mathematics | Boolean | math_is_polygonal |
650 | 2 Keys Keyboard | Mathematics | Sum | Sieve , factor_sum |
744 | Find Smallest Letter Greater Than Target | Binary search | Character | binary_search_min |
2119 | A Number After a Double Reversal | Mathematics | Boolean | math_reverse |
2400 | Number of Ways to Reach a Position After Exactly k Steps | Combinatorics | Binomial coefficient | mod_binomial_range |
2427 | Number of Common Factors | Mathematics | Count | gcd |
2507 | Smallest Value After Replacing With Sum of Prime Factors | Mathematics | Minimum | Sieve , factor_sum |
2520 | Count the Digits That Divide a Number | Mathematics | Count | |
2521 | Distinct Prime Factors of a Product Array | Mathematics | Count | FactorIterator , Sieve |
2544 | Alternating Digit Sum | Mathematics | Sum | |
2550 | Monkey Move | Combinatorics | Power | mod_pow |