Squaring a Sorted Array with Two Pointers

🚀 Day 18 of #100DaysOfCode 📌 LeetCode 977 – Squares of a Sorted Array Today’s problem was about transforming a sorted array (with possible negative numbers) into a new array of squared values that remains sorted. 💡 Approach Used: Two Pointers Instead of squaring all elements and sorting again (O(n log n)), I applied the Two Pointer technique to compare absolute values from both ends and filled the result array from the back. 🧠 Key Learnings: ✔️ Importance of optimal thinking over brute force ✔️ How negative numbers affect sorting after squaring ✔️ Efficient use of Two Pointers in array problems ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) 🔍 Problem Pattern: Array + Two Pointers Consistency is the key — showing up every day and improving step by step! 💪 #Day18 #100DaysOfCode #LeetCode #DSA #Python #CodingJourney #BTech #DataStructures

  • text

GREAT WORK LEGEND🫡🙏 KEEP GOING AND KEEP SHINING 🙏🫡

Like
Reply

To view or add a comment, sign in

Explore content categories