|
| 1 | +# Module 2: Arrays and Strings |
| 2 | + |
| 3 | +In this module, we get into the core concepts of arrays and strings, which are fundamental data structures in programming. We will explore various algorithms and techniques to manipulate and solve problems using these structures. |
| 4 | + |
| 5 | +## Topics Covered |
| 6 | + |
| 7 | +1. **Array Basics**: Understanding how arrays work and their properties. |
| 8 | +2. **String Manipulation**: Techniques for modifying and analyzing strings. |
| 9 | +3. **Common Algorithms**: Including two-pointer techniques, sliding window algorithms, and prefix sums. |
| 10 | + |
| 11 | +## Learning Objectives |
| 12 | + |
| 13 | +- Understand the properties and operations of arrays and strings. |
| 14 | +- Implement common algorithms involving arrays and strings. |
| 15 | +- Solve key problems that utilize arrays and strings efficiently. |
| 16 | + |
| 17 | +## Key Problems |
| 18 | + |
| 19 | +### 1. Reverse a String |
| 20 | + |
| 21 | +- **Description**: This problem involves reversing the characters in a given string. |
| 22 | +- **Implementation**: See [ReverseString.java](ReverseString.java) for the code. |
| 23 | + |
| 24 | +### 2. Sliding Window |
| 25 | + |
| 26 | +- **Description**: This technique is useful for solving problems that require tracking a subset of elements within an array or string over a moving window. |
| 27 | +- **Implementation**: See [SlidingWindow.java](SlidingWindow.java) for the code. |
| 28 | + |
| 29 | +### 3. Prefix Sum |
| 30 | + |
| 31 | +- **Description**: The prefix sum is a technique used to optimize the calculation of sum queries over an array. |
| 32 | +- **Implementation**: See [PrefixSum.java](PrefixSum.java) for the code. |
| 33 | + |
| 34 | +### 4. Squares of a Sorted Array |
| 35 | + |
| 36 | +- **Description**: This problem requires transforming a given sorted array of integers by squaring each number and returning a new sorted array containing the squares. The output must also be sorted in non-decreasing order. |
| 37 | +- **Implementation**: See [SquaresOfSortedArray.java](SquaresOfSortedArray.java) |
| 38 | + |
| 39 | +### 5. Maximum Average Subarray |
| 40 | + |
| 41 | +- **Description**: The goal is to find the maximum average of a subarray with a fixed size k within a given integer array. This requires calculating the sum of each subarray of size k and determining the maximum sum, which can then be converted to an average by dividing by k. |
| 42 | +- **Implementation**: See [MaximumAverageSubarray.java](MaximumAverageSubarray.java) for the code. |
| 43 | + |
| 44 | +### 6. K- Radius Subarray Averages |
| 45 | + |
| 46 | +- **Description**: This problem requires calculating the average of elements in a subarray that includes k elements on both sides of each element, resulting in a new array of averages. If there are fewer than k elements on either side, those positions will have a default value of 0. |
| 47 | +- **Implementation**: See [ KRadiusSubarrayAverages.java]( KRadiusSubarrayAverages.java) for the code. |
| 48 | + |
| 49 | +## Quiz Questions: |
| 50 | +What is the time complexity of reversing a string? |
| 51 | +In the sliding window technique, how do you handle overlapping windows? |
| 52 | +What is the purpose of a prefix sum array? |
| 53 | +When squaring the elements of a sorted array, what is the time complexity of the algorithm? |
| 54 | +How is the maximum average subarray calculated? |
| 55 | + |
| 56 | +## Further Reading: |
| 57 | +- [Introduction to Arrays](https://www.geeksforgeeks.org/array-data-structure/) |
| 58 | +- [String Manipulation in Java](https://www.javatpoint.com/java-string-manipulation) |
| 59 | +- [Sliding Window Technique](https://www.educative.io/edpresso/sliding-window-technique-in-algorithms) |
| 60 | +- [Prefix Sum Array Explained](https://www.geeksforgeeks.org/prefix-sum-array-optimized-sum-queries/) |
| 61 | +- [Sorting Algorithms](https://www.geeksforgeeks.org/sorting-algorithms/) |
0 commit comments