Squares of a Sorted Array | 2 Approaches | Follow Up | Leetcode 977
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 24th Video of our Playlist "Leetcode Easy : Popular Interview Problems".
In this video we will try to solve a good practice problem : Squares of a Sorted Array | Leetcode 977
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Squares of a Sorted Array | 2 Approaches | Follow Up | Leetcode 977
Company Tags : ByteDance, Meta
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Arrays/Leetcode%20Easy/Squares%20of%20a%20Sorted%20Array.cpp
Leetcode Link : https://leetcode.com/problems/squares-of-a-sorted-array/
My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My Recursion Concepts Playlist : https://www.youtube.com/watch?v=pfb1Zduesi8&list=PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Approach Summary :
Approach-1:
Algorithm: Square each element and then Sort the array.
Time Complexity (T.C): O(nlogn) , Space Complexity (S.C): O(1)
Approach-2:
Algorithm: Use two pointers to compare and fill the result array. Traverse the array once.
Time Complexity (T.C): O(n) , Space Complexity (S.C): O(1) (excluding result array space)
Summary: Approach-1 sorts squared values, leading to O(nlogn) time. Approach-2, optimized for sorted arrays, achieves O(n) time by filling the result array in a single pass. Approach-2 is preferred for larger arrays due to its lower time complexity.
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
✨ Timelines✨
00:00 - Introduction
01:06 - Approach-1
01:48 - Approach-2
04:01 - Time & Space
04:32 - Coding it up
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #2024 #newyear2024