Home

Awesome

Exercises for Intro to Algorithms and Data Structures in C++

Welcome to the exercises. This is where the magic happens!

1. Getting started with C++

2. Programming Fundamentals -I

3. Programming Fundamentals -II

<!-- Challenges- Fundamentals -------------------- --> <blockquote> <details> <summary> Excercise-01 : Fundamentals &nbsp; [16 Questions] </summary> <br> <table> <tr> <td>S.No</td> <td>Exercise <img width=600/> </td> </tr> <tr> <td>1</td> <td> <a href="exercise_01_fundamentals/01_von_neuman_loves_binary.cpp"> Von Neuman Loves Binary </a> </td> </tr> <tr> <td>2</td> <td> <a href="exercise_01_fundamentals/02_pythagoras_triplets.cpp"> Pythagoras Triplets </a> </td> </tr> <tr> <td>3</td> <td> <a href="exercise_01_fundamentals/03_fahrenheit_to_celsius.cpp"> Fahrenheit to Celsius conversions </a> </td> </tr> <tr> <td>4</td> <td> <a href="exercise_01_fundamentals/04_simple_input.cpp"> Simple Input </a> </td> </tr> <tr> <td>5</td> <td> <a href="exercise_01_fundamentals/05_print_series.cpp"> Print Series </a> </td> </tr> <tr> <td>6</td> <td> <a href="exercise_01_fundamentals/06_traffic_odd_even.cpp"> Traffic Odd Even </a> </td> </tr> <tr> <td>7</td> <td> <a href="exercise_01_fundamentals/07_transport_fare.cpp"> Transport Fare Problem </a> </td> </tr> <tr> <td>8</td> <td> <a href="exercise_01_fundamentals/08_counts_digits.cpp"> Count Digits </a> </td> </tr> <tr> <td>9</td> <td> <a href="exercise_01_fundamentals/09_basic_calculator.cpp"> Basic Calculator </a> </td> </tr> <tr> <td>10</td> <td> <a href="exercise_01_fundamentals/10_increase_decrease_sequence.cpp"> Increase Decrease Sequence </a> </td> </tr> <tr> <td>11</td> <td> <a href="exercise_01_fundamentals/11_decimal_tooctal.cpp"> Decimal to Octal </a> </td> </tr> <tr> <td>12</td> <td> <a href="exercise_01_fundamentals/12_quadratic_equation.cpp"> Quadratic Equation </a> </td> </tr> <tr> <td>13</td> <td> <a href="exercise_01_fundamentals/13_is_armstrong_number.cpp"> Armstrong Number </a> </td> </tr> <tr> <td>14</td> <td> <a href="exercise_01_fundamentals/14_check_prime.cpp"> Check Prime </a> </td> </tr> <tr> <td>15</td> <td> <a href="exercise_01_fundamentals/15_binary_to_decimal.cpp"> Binary to Decimal </a> </td> </tr> <tr> <td>16</td> <td> <a href="exercise_01_fundamentals/16_print_reverse.cpp"> Print Reverse </a> </td> </tr> </table> </details> </blockquote> <!-- Challenges- Patterns -------------------- --> <blockquote> <details> <summary> Excercise-02 : Patterns &nbsp; [14 Questions] </summary> <br> <table> <tr> <td>S.No</td> <td>Excercise <img width=600/> </td> </tr> <tr> <td>1</td> <td> <a href="exercise_02_patterns/01_fibonacci_pattern.cpp"> Fibonacci Pattern </a> </td> </tr> <tr> <td>2</td> <td> <a href="exercise_02_patterns/02_pattern_I.cpp"> Pattern-I </a> </td> </tr> <tr> <td>3</td> <td> <a href="exercise_02_patterns/03_pattern_II.cpp"> Patterns-II </a> </td> </tr> <tr> <td>4</td> <td> <a href="exercise_02_patterns/04_pattern_mountain.cpp"> Pattern Mountain </a> </td> </tr> <tr> <td>5</td> <td> <a href="exercise_02_patterns/05_pattern_with_zero.cpp"> Pattern with Zeros </a> </td> </tr> <tr> <td>6</td> <td> <a href="exercise_02_patterns/06_pattern_triangle.cpp"> Pattern Triangle </a> </td> </tr> <tr> <td>7</td> <td> <a href="exercise_02_patterns/07_double_sideed_arrow.cpp"> Pattern Double Sided Arrow </a> </td> </tr> <tr> <td>8</td> <td> <a href="exercise_02_patterns/08_pattern%20_inverted_HourGlass.cpp"> Pattern Inverted HourGlass </a> </td> </tr> <tr> <td>9</td> <td> <a href="exercise_02_patterns/09_swastika_pattern.cpp"> 卐 Swastika Pattern </a> </td> </tr> <tr> <td>10</td> <td> <a href="exercise_02_patterns/10_hollow_diamond_pattern.cpp"> Hollow Diamond Pattern </a> </td> </tr> <tr> <td>11</td> <td> <a href="exercise_02_patterns/11_hollow_rhombus_pattern.cpp"> Hollow Rhombus Pattern </a> </td> </tr> <tr> <td>12</td> <td> <a href="exercise_02_patterns/12_pascal_triangle_1.cpp"> Pascal Triangle </a> </td> </tr> <tr> <td>13</td> <td> <a href="exercise_02_patterns/13_pattern_and_star_1.cpp"> Pattern Numbers & Stars - 1 </a> </td> </tr> <tr> <td>14</td> <td> <a href="exercise_02_patterns/14_pattern_and_star_2.cpp"> Pattern Numbers & Stars - 2 </a> </td> </tr> </table> </details> </blockquote>

4. Functions

5. Arrays

6. 2D Arrays

7. Character Arrays

8. Strings

9. 2D Array Problems

<!-- Challenges - Arrays-------------------- --> <blockquote> <details> <summary> Excercise-03 : Arrays &nbsp; [15 Questions] </summary> <br> <table> <tr> <td>S.No</td> <td>Excercise <img width=600/> </td> </tr> <tr> <td>1</td> <td> <a href="exercise_03_arrays/01_max_value_in_array.cpp"> Maximum Value in Array </a> </td> </tr> <tr> <td>2</td> <td> <a href="exercise_03_arrays/02_wave_print_column_wise.cpp"> Wave print column wise </a> </td> </tr> <tr> <td>3</td> <td> <a href="exercise_03_arrays/03_target_sum_pairs.cpp"> Target Sum Pairs </a> </td> </tr> <tr> <td>4</td> <td> <a href="exercise_03_arrays/04_target_sum_triplets.cpp"> Target Sum Triplets </a> </td> </tr> <tr> <td>5</td> <td> <a href="exercise_03_arrays/05_rain_water_harvesting.cpp"> Rain Water Harvesting </a> </td> </tr> <tr> <td>6</td> <td> <a href="exercise_03_arrays/06_maximum_subarray_sum.cpp"> Maximum Subarray Sum </a> </td> </tr> <tr> <td>7</td> <td> <a href="exercise_03_arrays/07_maximum_circular_sum.cpp"> Maximum Circular Sum </a> </td> </tr> <tr> <td>8</td> <td> <a href="exercise_03_arrays/08_maximum_length_bitonic_subarray.cpp"> Maximum length Bitonic Subarray </a> </td> </tr> <tr> <td>9</td> <td> <a href="exercise_03_arrays/09_array_spiral_print_anticlockwise.cpp"> Array Spiral Print Anticlockwise </a> </td> </tr> <tr> <td>10</td> <td> <a href="exercise_03_arrays/10_rotate_image_90_degree.cpp"> Rotate Image(N x N Array) </a> </td> </tr> <tr> <td>11</td> <td> <a href="exercise_03_arrays/11_chewbacca_and_number.cpp"> Chewbacca and Number </a> </td> </tr> <tr> <td>12</td> <td> <a href="exercise_03_arrays/12_broken_calculator.cpp"> Broken Calculator </a> </td> </tr> <tr> <td>13</td> <td> <a href="exercise_03_arrays/13_matrix_search.cpp"> Matrix Search </a> </td> </tr> <tr> <td>14</td> <td> <a href="exercise_03_arrays/14_sum_of_two_arrays.cpp"> Sum of Two Arrays </a> </td> </tr> <tr> <td>15</td> <td> <a href="exercise_03_arrays/15_median_of_sorted_array.cpp"> Median of Sorted Arrays </a> </td> </tr> </table> </details> </blockquote> <!-- Challenges - Strings -------------------- --> <blockquote> <details> <summary> Excercise-04 : Strings &nbsp; [11 Questions] </summary> <br> <table> <tr> <td>S.No</td> <td>Excercise <img width=600/> </td> </tr> <tr> <td>1</td> <td> <a href="exercise_04_strings/01_difference_in_ascii_codes.cpp"> Difference in Ascii Codes </a> </td> </tr> <tr> <td>2</td> <td> <a href="exercise_04_strings/02_ultra_fast_mathematicians.cpp"> Ultra Fast Mathematicians </a> </td> </tr> <tr> <td>3</td> <td> <a href="exercise_04_strings/03_max_frequency_character.cpp"> Max Frequency Character </a> </td> </tr> <tr> <td>4</td> <td> <a href="exercise_04_strings/04_string_compression.cpp"> String Compression </a> </td> </tr> <tr> <td>5</td> <td> <a href="exercise_04_strings/05_is_palindrome.cpp"> Is Palindrome? (Recursive) </a> </td> </tr> <tr> <td>6</td> <td> <a href="exercise_04_strings/06_max_length_substring_after_k_changes.cpp"> Maximum length substring having all same characters after k changes </a> </td> </tr> <tr> <td>7</td> <td> <a href="exercise_04_strings/07_find_words_from_camelcase_string.cpp"> Find all words in CamelCase string </a> </td> </tr> <tr> <td>8</td> <td> <a href="exercise_04_strings/08_character_type.cpp"> Character Type </a> </td> </tr> <tr> <td>9</td> <td> <a href="exercise_04_strings/09_lower_upper.cpp"> Lower Upper </a> </td> </tr> <tr> <td>10</td> <td> <a href="exercise_04_strings/10_person_and_magical_park.cpp"> Person and Magical Park </a> </td> </tr> <tr> <td>11</td> <td> <a href="exercise_04_strings/11_find_csd_number.cpp"> Find CSD Number </a> </td> </tr> </table> </details> </blockquote>

10. Pointers

11. Dynamic Memory Allocation

12. Algorithms STL

<!-- Challenges - Algorithms STL -------------------- --> <blockquote> <details> <summary> Excercise-05 : Algorithms STL &nbsp; [2 Questions] </summary> <br> <table> <tr> <td>S.No</td> <td>Excercise <img width=600/> </td> </tr> <tr> <td>1</td> <td> <a href="exercise_05_algorithms_stl/01_next_permutation.cpp"> Next Permutation </a> </td> </tr> <tr> <td>2</td> <td> <a href="exercise_05_algorithms_stl/02_activity_selection_problems.cpp"> Activity Selection Problems </a> </td> </tr> </table> </details> </blockquote>

13. Binary Search (Divide & Conquer)

<!-- Challenges - Sorting & Searching -------------------- --> <blockquote> <details> <summary> Excercise-06 : Sorting & Searching. &nbsp; [16 Questions] </summary> <br> <table> <tr> <td>S.No</td> <td>Excercise <img width=600/> </td> </tr> <tr> <td>1</td> <td> <a href="exercise_06_sorting_n_searching/01_kth_root.cpp"> Kth Root </a> </td> </tr> <tr> <td>2</td> <td> <a href="exercise_06_sorting_n_searching/02_binary_search.cpp"> Binary Search </a> </td> </tr> <tr> <td>3</td> <td> <a href="exercise_06_sorting_n_searching/03_book_allocation_problem.cpp"> Book Allocation Problem </a> </td> </tr> <tr> <td>4</td> <td> <a href="exercise_06_sorting_n_searching/04_sorting_in_linear_time.cpp"> Sorting in Linear Time </a> </td> </tr> <tr> <td>5</td> <td> <a href="exercise_06_sorting_n_searching/05_bubble_sort.cpp"> Bubble Sort </a> </td> </tr> <tr> <td>6</td> <td> <a href="exercise_06_sorting_n_searching/06_aggressive_cows.cpp"> Aggressive Cows </a> </td> </tr> <tr> <td>7</td> <td> <a href="exercise_06_sorting_n_searching/07_selection_sort.cpp"> Selection Sort </a> </td> </tr> <tr> <td>8</td> <td> <a href="exercise_06_sorting_n_searching/08_painter_problem.cpp"> Painter Problem </a> </td> </tr> <tr> <td>9</td> <td> <a href="exercise_06_sorting_n_searching/09_counting_sort.cpp"> Counting Sort </a> </td> </tr> <tr> <td>10</td> <td> <a href="exercise_06_sorting_n_searching/10_insertion_sort.cpp"> Insertion Sort </a> </td> </tr> <tr> <td>11</td> <td> <a href="exercise_06_sorting_n_searching/11_winning_scholarship.cpp"> Winning Scholarship </a> </td> </tr> <tr> <td>12</td> <td> <a href="exercise_06_sorting_n_searching/12_string_sort.cpp"> String Sort </a> </td> </tr> <tr> <td>13</td> <td> <a href="exercise_06_sorting_n_searching/13_help_aman_to_search.cpp"> Help Aman to Search </a> </td> </tr> <tr> <td>14</td> <td> <a href="exercise_06_sorting_n_searching/14_find_upper_and_lower_bound.cpp"> Find Upper and Lower bound </a> </td> </tr> <tr> <td>15</td> <td> <a href="exercise_06_sorting_n_searching/15_pivot_of_sorted_and_rotated_array.cpp"> Pivot of Sorted and Rotated </a> </td> </tr> <tr> <td>16</td> <td> <a href="exercise_06_sorting_n_searching/16_sort_game.cpp"> Sort Game </a> </td> </tr> </table> </details> </blockquote>

14. Bit Manipulation

<!-- Challenges - Bitmasking ----------------------> <blockquote> <details> <summary> Excercise-07 : Bitmasking &nbsp; [8 Questions] </summary> <br> <table> <tr> <td>S.No</td> <td>Excercise <img width=600/> </td> </tr> <tr> <td>1</td> <td> <a href="exercise_07_bitmasking/01_playing_with_bits.cpp"> Playing With Bits </a> </td> </tr> <tr> <td>2</td> <td> <a href="exercise_07_bitmasking/02_unique_number_I.cpp"> Unique Number - I </a> </td> </tr> <tr> <td>3</td> <td> <a href="exercise_07_bitmasking/03_xor_profit_problem.cpp"> XOR Profit Problem </a> </td> </tr> <tr> <td>4</td> <td> <a href="exercise_07_bitmasking/04_count_set_bits.cpp"> Count Set Bits </a> </td> </tr> <tr> <td>5</td> <td> <a href="exercise_07_bitmasking/05_unique_number_II.cpp"> Unique Numbers - II </a> </td> </tr> <tr> <td>6</td> <td> <a href="exercise_07_bitmasking/06_unique_number_III.cpp"> Unique Numbers - III </a> </td> </tr> <tr> <td>7</td> <td> <a href="exercise_07_bitmasking/07_incredible_hulk.cpp"> Incredible Hulk </a> </td> </tr> <tr> <td>8</td> <td> <a href="exercise_07_bitmasking/08_power.cpp"> Power(O(logn)) </a> </td> </tr> </table> </details> </blockquote>

15. Number Theory Basics

<!-- Challenges - Number Theory ----------------------> <blockquote> <details> <summary> Excercise-08 : Number Theory &nbsp; [7 Questions] </summary> <br> <table> <tr> <td>S.No</td> <td>Excercise <img width=600/> </td> </tr> <tr> <td>1</td> <td> <a href="exercise_08_number_theory/01_modular_exponentiation.cpp"> Modular Exponentiation </a> </td> </tr> <tr> <td>2</td> <td> <a href="exercise_08_number_theory/02_raman_and_primes.cpp"> Raman and Primes </a> </td> </tr> <tr> <td>3</td> <td> <a href="exercise_08_number_theory/03_gcd.cpp"> GCD </a> </td> </tr> <tr> <td>4</td> <td> <a href="exercise_08_number_theory/04_amit_loves_candy.cpp"> Amit Loves Candy </a> </td> </tr> <tr> <td>5</td> <td> <a href="exercise_08_number_theory/05_divisible_subarray.cpp"> Divisible Subarray </a> </td> </tr> <tr> <td>6</td> <td> <a href="exercise_08_number_theory/06_lcm.cpp"> LCM </a> </td> </tr> <tr> <td>7</td> <td> <a href="exercise_08_number_theory/07_prime_visits.cpp"> Prime Visits </a> </td> </tr> </table> </details> </blockquote>

16. Recursion-I Basics

17. Recursion-II Implementation

18. Recursion-III Quick Thinking

19. Recursion-IV Subset Based

20. Recursion-V Backtracking

21. More Sorting Techniques & Problems

22. Space Time Complexity Analysis

<!-- Challenges - Space Time Complexity Analysis ----------------------> <blockquote> <details> <summary> Excercise-10 : Space Time Complexity Analysis &nbsp; [15 Questions] </summary> <br> <table> <tr> <td>S.No</td> <td>Excercise <img width=600/> </td> </tr> <tr> <td>1</td> <td> <a href="exercise_10_space_time_complexity/01_exercise_time_space_complexity.pdf"> 15 Questions with Answers </a> </td> </tr> </table> </details> </blockquote>

23. Object Oriented Programming Concepts

24. Generic Programming in CPP

25. Vectors

26. Linked Lists

^^ Miscellaneous

<!-- Challenges - Misc ----------------------> <blockquote> <details> <summary> Excercise-11 : Misc. &nbsp; [5 Questions] </summary> <br> <table> <tr> <td>S.No</td> <td>Excercise <img width=600/> </td> </tr> <tr> <td>1</td> <td> <a href="misc/"> Challange01 </a> </td> </tr> </table> </details> </blockquote>