An open API service indexing awesome lists of open source software.

https://github.com/fritzrehde/competitive-programming

My solutions to LeetCode, ICPC, Hackerrank problems
https://github.com/fritzrehde/competitive-programming

algorithms competitive-programming data-structures hackerrank icpc leetcode python

Last synced: 14 days ago
JSON representation

My solutions to LeetCode, ICPC, Hackerrank problems

Awesome Lists containing this project

README

        

# Competitive Programming

This repository contains my solutions to competitive programming problems from various online platforms.

Each of the code solution files contains the problem description, several (differently performing) implementations, as well as time and space complexity analysis.

## Table of Contents

- [LeetCode](#leetcode)
- [Hackerrank](#hackerrank)

## [LeetCode](https://leetcode.com)

| # | Difficulty | Problem Title | Implementation |
|:--|:-----------|:--------------|:---------------|
| 1 | Easy | [Two Sum](https://leetcode.com/problems/two-sum/) | [Python](./leetcode/0001-two-sum/two_sum.py) |
| 2 | Medium | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | [Python](./leetcode/0002-add-two-numbers/add_two_numbers.py) |
| 3 | Medium | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | [Python](./leetcode/0003-longest-substring-without-repeating-characters/longest_substring_without_repeating_characters.py) |
| 4 | Hard | [Median Of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) | [Python](./leetcode/0004-median-of-two-sorted-arrays/median_of_two_sorted_arrays.py) |
| 5 | Medium | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) | [Python](./leetcode/0005-longest-palindromic-substring/longest_palindromic_substring.py) |
| 6 | Medium | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion/) | [Python](./leetcode/0006-zigzag-conversion/zigzag_conversion.py) |
| 7 | Medium | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [Python](./leetcode/0007-reverse-integer/reverse_integer.py) |
| 8 | Medium | [String To Integer (Atoi)](https://leetcode.com/problems/string-to-integer-atoi/) | [Python](./leetcode/0008-string-to-integer-atoi/string_to_integer_atoi.py) |
| 10 | Hard | [Regular Expression Matching](https://leetcode.com/problems/regular-expression-matching) | [Python](./leetcode/0010-regular-expression-matching/regular_expression_matching.py) |
| 11 | Medium | [Container With Most Water](https://leetcode.com/problems/container-with-most-water/) | [Python](./leetcode/0011-container-with-most-water/container_with_most_water.py) |
| 13 | Easy | [Roman to Integer](https://leetcode.com/problems/roman-to-integer) | [Python](./leetcode/0013-roman-to-integer/roman_to_integer.py) |
| 14 | Easy | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | [Python](./leetcode/0014-longest-common-prefix/longest_common_prefix.py) |
| 15 | Medium | [3Sum](https://leetcode.com/problems/3sum/) | [Python](./leetcode/0015-3sum/3sum.py) |
| 17 | Medium | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number) | [Python](./leetcode/0017-letter-combinations-of-a-phone-number/letter_combinations_of_a_phone_number.py) |
| 19 | Medium | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list) | [Python](./leetcode/0019-remove-nth-node-from-end-of-list/remove_nth_node_from_end_of_list.py) |
| 20 | Easy | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](./leetcode/0020-valid-parentheses/valid_parentheses.py) |
| 21 | Easy | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [Python](./leetcode/0021-merge-two-sorted-lists/merge_two_sorted_lists.py) |
| 22 | Medium | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses/) | [Python](./leetcode/0022-generate-parentheses/generate_parentheses.py) |
| 26 | Easy | [Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array) | [Python](./leetcode/0026-remove-duplicates-from-sorted-array/remove_duplicates_from_sorted_array.py) |
| 28 | Easy | [Find The Index Of The First Occurrence In A String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/) | [Python](./leetcode/0028-find-the-index-of-the-first-occurrence-in-a-string/find_the_index_of_the_first_occurrence_in_a_string.py) |
| 36 | Medium | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku) | [Python](./leetcode/0036-valid-sudoku/valid_sudoku.py) |
| 42 | Hard | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water) | [Python](./leetcode/0042-trapping-rain-water/trapping_rain_water.py) |
| 45 | Medium | [Jump Game II](https://leetcode.com/problems/jump-game-ii/) | [Python](./leetcode/0045-jump-game-ii/jump_game_ii.py) |
| 49 | Medium | [Group Anagrams](https://leetcode.com/problems/group-anagrams) | [Python](./leetcode/0049-group-anagrams/group_anagrams.py) |
| 50 | Medium | [Pow(X, N)](https://leetcode.com/problems/powx-n/) | [Python](./leetcode/0050-powx-n/powx_n.py) |
| 51 | Hard | [N-Queens](https://leetcode.com/problems/n-queens/) | [Python](./leetcode/0051-n-queens/n_queens.py) |
| 53 | Medium | [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) | [Python](./leetcode/0053-maximum-subarray/maximum_subarray.py) |
| 54 | Medium | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix) | [Python](./leetcode/0054-spiral-matrix/spiral_matrix.py) |
| 55 | Medium | [Jump Game](https://leetcode.com/problems/jump-game) | [Python](./leetcode/0055-jump-game/jump_game.py) |
| 70 | Easy | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) | [Python](./leetcode/0070-climbing-stairs/climbing_stairs.py) |
| 94 | Easy | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) | [Python](./leetcode/0094-binary-tree-inorder-traversal/binary_tree_inorder_traversal.py) |
| 100 | Easy | [Same Tree](https://leetcode.com/problems/same-tree) | [Python](./leetcode/0100-same-tree/same_tree.py) |
| 121 | Easy | [Best Time To Buy And Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) | [Python](./leetcode/0121-best-time-to-buy-and-sell-stock/best_time_to_buy_and_sell_stock.py) |
| 125 | Easy | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/) | [Python](./leetcode/0125-valid-palindrome/valid_palindrome.py) |
| 128 | Medium | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence) | [Python](./leetcode/0128-longest-consecutive-sequence/longest_consecutive_sequence.py) |
| 133 | Medium | [Clone Graph](https://leetcode.com/problems/clone-graph) | [Python](./leetcode/0133-clone-graph/clone_graph.py) |
| 136 | Easy | [Single Number](https://leetcode.com/problems/single-number) | [Python](./leetcode/0136-single-number/single_number.py) |
| 144 | Easy | [Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal/) | [Python](./leetcode/0144-binary-tree-preorder-traversal/binary_tree_preorder_traversal.py) |
| 145 | Easy | [Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal/) | [Python](./leetcode/0145-binary-tree-postorder-traversal/binary_tree_postorder_traversal.py) |
| 151 | Medium | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) | [Python](./leetcode/0151-reverse-words-in-a-string/reverse_words_in_a_string.py) |
| 152 | Medium | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray) | [Python](./leetcode/0152-maximum-product-subarray/maximum_product_subarray.py) |
| 153 | Medium | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | [Python](./leetcode/0153-find-minimum-in-rotated-sorted-array/find_minimum_in_rotated_sorted_array.py) |
| 155 | Medium | [Min Stack](https://leetcode.com/problems/min-stack) | [Python](./leetcode/0155-min-stack/min_stack.py) |
| 167 | Medium | [Two Sum Ii - Input Array Is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) | [Python](./leetcode/0167-two-sum-ii-input-array-is-sorted/two_sum_ii_input_array_is_sorted.py) |
| 179 | Medium | [Largest Number](https://leetcode.com/problems/largest-number/) | [Python](./leetcode/0179-largest-number/largest_number.py) |
| 189 | Medium | [Rotate Array](https://leetcode.com/problems/rotate-array) | [Python](./leetcode/0189-rotate-array/rotate_array.py) |
| 198 | Medium | [House Robber](https://leetcode.com/problems/house-robber) | [Python](./leetcode/0198-house-robber/house_robber.py) |
| 200 | Medium | [Number of Islands](https://leetcode.com/problems/number-of-islands) | [Python](./leetcode/0200-number-of-islands/number_of_islands.py) |
| 206 | Easy | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list) | [Python](./leetcode/0206-reverse-linked-list/reverse_linked_list.py) |
| 207 | Medium | [Course Schedule](https://leetcode.com/problems/course-schedule/) | [Python](./leetcode/0207-course-schedule/course_schedule.py) |
| 210 | Medium | [Course Schedule Ii](https://leetcode.com/problems/course-schedule-ii/) | [Python](./leetcode/0210-course-schedule-ii/course_schedule_ii.py) |
| 217 | Easy | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate) | [Python](./leetcode/0217-contains-duplicate/contains_duplicate.py) |
| 225 | Easy | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) | [Python](./leetcode/0225-implement-stack-using-queues/implement_stack_using_queues.py) |
| 226 | Easy | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) | [Python](./leetcode/0226-invert-binary-tree/invert_binary_tree.py) |
| 232 | Easy | [Implement Queue using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) | [Python](./leetcode/0232-implement-queue-using-stacks/implement_queue_using_stacks.py) |
| 238 | Medium | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self) | [Python](./leetcode/0238-product-of-array-except-self/product_of_array_except_self.py) |
| 242 | Easy | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | [Python](./leetcode/0242-valid-anagram/valid_anagram.py) |
| 263 | Easy | [Ugly Number](https://leetcode.com/problems/ugly-number) | [Python](./leetcode/0263-ugly-number/ugly_number.py) |
| 264 | Medium | [Ugly Number II](https://leetcode.com/problems/ugly-number-ii) | [Python](./leetcode/0264-ugly-number-ii/ugly_number_ii.py) |
| 268 | Easy | [Missing Number](https://leetcode.com/problems/missing-number) | [Python](./leetcode/0268-missing-number/missing_number.py) |
| 271 | Medium | [Encode And Decode Strings](https://leetcode.com/problems/encode-and-decode-strings/) | [Python](./leetcode/0271-encode-and-decode-strings/encode_and_decode_strings.py) |
| 292 | Easy | [Nim Game](https://leetcode.com/problems/nim-game/) | [Python](./leetcode/0292-nim-game/nim_game.py) |
| 300 | Medium | [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence) | [Python](./leetcode/0300-longest-increasing-subsequence/longest_increasing_subsequence.py) |
| 345 | Easy | [Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string) | [Python](./leetcode/0345-reverse-vowels-of-a-string/reverse_vowels_of_a_string.py) |
| 347 | Medium | [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements) | [C++](./leetcode/0347-top-k-frequent-elements/solution.cpp) |
| 370 | Medium | [Range Addition](https://leetcode.com/problems/range-addition) | [Python](./leetcode/0370-range-addition/range_addition.py) |
| 430 | Medium | [Flatten a Multilevel Doubly Linked List](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list) | [Python](./leetcode/0430-flatten-a-multilevel-doubly-linked-list/flatten_a_multilevel_doubly_linked_list.py) |
| 443 | Medium | [String Compression](https://leetcode.com/problems/string-compression) | [Python](./leetcode/0443-string-compression/string_compression.py) |
| 450 | Medium | [Delete Node In A Bst](https://leetcode.com/problems/delete-node-in-a-bst/) | [Python](./leetcode/0450-delete-node-in-a-bst/delete_node_in_a_bst.py) |
| 476 | Easy | [Number Complement](https://leetcode.com/problems/number-complement) | [Python](./leetcode/0476-number-complement/number_complement.py) |
| 485 | Easy | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) | [Python](./leetcode/0485-max-consecutive-ones/max_consecutive_ones.py) |
| 487 | Medium | [Max Consecutive Ones Ii](https://leetcode.com/problems/max-consecutive-ones-ii) | [Python](./leetcode/0487-max-consecutive-ones-ii/max_consecutive_ones_ii.py) |
| 496 | Easy | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) | [Python](./leetcode/0496-next-greater-element-i/next_greater_element_i.py) |
| 503 | Medium | [Next Greater Element II](https://leetcode.com/problems/next-greater-element-ii) | [Python](./leetcode/0503-next-greater-element-ii/next_greater_element_ii.py) |
| 557 | Easy | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) | [Python](./leetcode/0557-reverse-words-in-a-string-iii/reverse_words_in_a_string_iii.py) |
| 572 | Easy | [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree) | [Python](./leetcode/0572-subtree-of-another-tree/subtree_of_another_tree.py) |
| 633 | Medium | [Sum Of Square Numbers](https://leetcode.com/problems/sum-of-square-numbers/) | [Python](./leetcode/0633-sum-of-square-numbers/sum_of_square_numbers.py) |
| 692 | Medium | [Top K Frequent Words](https://leetcode.com/problems/top-k-frequent-words/) | [Python](./leetcode/0692-top-k-frequent-words/top_k_frequent_words.py) |
| 701 | Medium | [Insert Into A Binary Search Tree](https://leetcode.com/problems/insert-into-a-binary-search-tree/) | [Python](./leetcode/0701-insert-into-a-binary-search-tree/insert_into_a_binary_search_tree.py) |
| 706 | Easy | [Design HashMap](https://leetcode.com/problems/design-hashmap) | [Python](./leetcode/0706-design-hashmap/design_hashmap.py) |
| 735 | Medium | [Asteroid Collision](https://leetcode.com/problems/asteroid-collision/) | [Python](./leetcode/0735-asteroid-collision/asteroid_collision.py) |
| 739 | Medium | [Daily Temperatures](https://leetcode.com/problems/daily-temperatures) | [Python](./leetcode/0739-daily-temperatures/daily_temperatures.py) |
| 743 | Medium | [Network Delay Time](https://leetcode.com/problems/network-delay-time/) | [Python](./leetcode/0743-network-delay-time/network_delay_time.py) |
| 771 | Easy | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) | [Python](./leetcode/0771-jewels-and-stones/jewels_and_stones.py) |
| 874 | Medium | [Walking Robot Simulation](https://leetcode.com/problems/walking-robot-simulation) | [Python](./leetcode/0874-walking-robot-simulation/walking_robot_simulation.py) |
| 945 | Medium | [Minimum Increment To Make Array Unique](https://leetcode.com/problems/minimum-increment-to-make-array-unique/) | [Python](./leetcode/0945-minimum-increment-to-make-array-unique/minimum_increment_to_make_array_unique.py) |
| 1052 | Medium | [Grumpy Bookstore Owner](https://leetcode.com/problems/grumpy-bookstore-owner/) | [Python](./leetcode/1052-grumpy-bookstore-owner/grumpy_bookstore_owner.py) |
| 1106 | Hard | [Parsing A Boolean Expression](https://leetcode.com/problems/parsing-a-boolean-expression) | [Python](./leetcode/1106-parsing-a-boolean-expression/parsing_a_boolean_expression.py) |
| 1137 | Easy | [N-Th Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number/) | [Python](./leetcode/1137-n-th-tribonacci-number/n-th_tribonacci_number.py) |
| 1143 | Medium | [Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence) | [Python](./leetcode/1143-longest-common-subsequence/longest_common_subsequence.py) |
| 1207 | Easy | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences) | [Python](./leetcode/1207-unique-number-of-occurrences/unique_number_of_occurrences.py) |
| 1275 | Easy | [Find Winner on a Tic Tac Toe Game](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | [Python](./leetcode/1275-find-winner-on-a-tic-tac-toe-game/find_winner_on_a_tic_tac_toe_game.py) |
| 1304 | Easy | [Find N Unique Integers Sum up to Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | [Python](./leetcode/1304-find-n-unique-integers-sum-up-to-zero/find_n_unique_integers_sum_up_to_zero.py) |
| 1431 | Easy | [Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies) | [Python](./leetcode/1431-kids-with-the-greatest-number-of-candies/kids_with_the_greatest_number_of_candies.py) |
| 1443 | Medium | [Minimum Time To Collect All Apples In A Tree](https://leetcode.com/problems/minimum-time-to-collect-all-apples-in-a-tree/) | [Python](./leetcode/1443-minimum-time-to-collect-all-apples-in-a-tree/minimum_time_to_collect_all_apples_in_a_tree.py) |
| 1518 | Easy | [Water Bottles](https://leetcode.com/problems/water-bottles/) | [Python](./leetcode/1518-water-bottles/water_bottles.py) |
| 1578 | Medium | [Minimum Time to Make Rope Colorful](https://leetcode.com/problems/minimum-time-to-make-rope-colorful) | [Python](./leetcode/1578-minimum-time-to-make-rope-colorful/minimum_time_to_make_rope_colorful.py) |
| 1636 | Easy | [Sort Array By Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency/) | [Python](./leetcode/1636-sort-array-by-increasing-frequency/sort_array_by_increasing_frequency.py) |
| 1653 | Medium | [Minimum Deletions to Make String Balanced](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced) | [Python](./leetcode/1653-minimum-deletions-to-make-string-balanced/minimum_deletions_to_make_string_balanced.py) |
| 1717 | Medium | [Maximum Score From Removing Substrings](https://leetcode.com/problems/maximum-score-from-removing-substrings/) | [Python](./leetcode/1717-maximum-score-from-removing-substrings/maximum_score_from_removing_substrings.py) |
| 1768 | Easy | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) | [Python](./leetcode/1768-merge-strings-alternately/merge_strings_alternately.py) |
| 1822 | Easy | [Sign of the Product of an Array](https://leetcode.com/problems/sign-of-the-product-of-an-array) | [Python](./leetcode/1822-sign-of-the-product-of-an-array/sign_of_the_product_of_an_array.py) |
| 1894 | Medium | [Find the Student that Will Replace the Chalk](https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk) | [Python](./leetcode/1894-find-the-student-that-will-replace-the-chalk/find_the_student_that_will_replace_the_chalk.py) |
| 2028 | Medium | [Find Missing Observations](https://leetcode.com/problems/find-missing-observations) | [Python](./leetcode/2028-find-missing-observations/find_missing_observations.py) |
| 2037 | Easy | [Minimum Number Of Moves To Seat Everyone](https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/) | [Python](./leetcode/2037-minimum-number-of-moves-to-seat-everyone/minimum_number_of_moves_to_seat_everyone.py) |
| 2085 | Easy | [Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence/) | [Python](./leetcode/2085-count-common-words-with-one-occurrence/count_common_words_with_one_occurrence.py) |
| 2259 | Easy | [Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result) | [Python](./leetcode/2259-remove-digit-from-number-to-maximize-result/remove_digit_from_number_to_maximize_result.py) |
| 3163 | Medium | [String Compression III](https://leetcode.com/problems/string-compression-iii) | [Python](./leetcode/3163-string-compression-iii/string_compression_iii.py) |

## [Hackerrank](https://www.hackerrank.com)

### Array

| Difficulty | Problem Title | Implementation |
|:-----------|:--------------|:---------------|
| Easy | [Arrays - DS](https://www.hackerrank.com/challenges/arrays-ds/problem) | [Python](./hackerrank/arrays-ds/arrays_ds.py) |
| Easy | [Array Left Rotation](https://www.hackerrank.com/challenges/array-left-rotation/problem) | [Python](./hackerrank/array-left-rotation/array_left_rotation.py) |

### Linked Lists

| Difficulty | Problem Title | Implementation |
|:-----------|:--------------|:---------------|
| Easy | [Reverse a Linked List](https://www.hackerrank.com/challenges/reverse-a-linked-list/problem) | [Python](./hackerrank/reverse-a-linked-list/reverse_a_linked_list.py) |

## Programming Language Choices

**Why Python?**
I think Python is a good language for quickly writing elegant and readable programs.
Of course, performance will be compromised, but performance is not the main goal of this project (for now).
I am mostly solving these puzzles to improve my knowledge in Algorithms and Data Structures.