Hello Everyone!
The final day of Week 10 was devoted to the techniques Arrays and Two-Pointer Techniques with particular attention to **operations and swapping of elements. These tasks were both artistic and meaningful, as they were tasks which called for clear logic and accurate performance. That was like putting order with full perfected strategies.
How the Day Went
-
String Compression (Medium Level)
- Task: Squish a string by replacing any character followed by any character of the same type in the string with the character, followed by the count, changing the string.
-
Approach:
- Used two pointers:
> write – It is a pointer that, in the compressed string, points at the location where it needs to write.
- read:
to iterate across the string so as to tally the exact count of consecutive characters. He wrote the character and its count(es), if it has more than one—indicated by the next number, at the position of thewrite
pointer and moved on.
- Used two pointers:
> write – It is a pointer that, in the compressed string, points at the location where it needs to write.
- What Made It Fun: Seeing the string update in real time as the characters and counts were typed felt like solving the current and live optimization problem.
-
Zeroes (Easy Difficulty)
- Task: Sort an array without using the sort method and swapping that keeps the zero at the end of an array while maintaining the order of other numbers.
-
Approach:
- Used a two-pointer strategy: A next pointers for keeping the next position of a non zero element. The other pointer which runs on the array in parallel to the first, swapping elements when a non-zero was found. – Checked that the array it took has to be modified in place without additional operations.
- What Made It Fun: That’s why it was such a relief to watch the zeros simply move to the end and leave all the other elements in some respectable order, akin to tidying up a messy desk and separating the items into sections.
What Stood Out Today
Precision with Two Pointers:
In order to reduce the number of possible operations, both problems used the two-pointer technique for fast search and iteration.In-Place Problem Solving:
In both tasks where the input is transformed directly without any additional space, the importance of solutions that work with naively-scarce resources has been emphasized.Step-by-Step Evolution:
C based real-time tracking also made it a lot easier and satisfying to track the changes whenever compressing a string or an array.
Key Takeaways
Two-Pointer Techniques Simplify Problems:
Example of such problems includes Move Zeroes, where this approach proves how operations can be made to run smoothly and remain organized.In-Place Modifications are Key:
In targeting such a goal, solutions are implemented to optimize resource usage, their method being titled String Compression.Clear Steps Lead to Clarity:
Thus, division of the solution into steps helps to minimize the likelihood of error, and when debugging, even with the most complex tasks, is easier.
Reflections
The String Compression problem was an excellent way of practicing approaching a problem both with traversal and modification efficiently, while **Move Zeroes was a great example of the use of the two-pointer technique in swapping elements of an array. Combined, these tasks brought Week 10 to a close with an emphasis on accuracy, speed, and real life applications.
What’s Next?
Since I am in week 10 ready to end, I am interested in the planning of week 11. The next up will be Dynamic Programming, Advanced aspects of Greedy algorithms and Backtracking problems
Thanks for reading this article to the end, hope you enjoyed the journey!! Let’s continue learning, problem solving and growing as a team.
Top comments (0)