Rearrange Array Alternately in O(1) space complexity and O(N) Time Complexity Geeksforgeeks Solution
Vložit
- čas přidán 2. 10. 2020
- This is the video under the series of DATA STRUCTURE & ALGORITHM. We are going to solve Questions from GeeksforGeeks Rearrange Array Alternately in O(N) Time Complexity and O(1) space Complexity. Given a sorted array of positive integers. Your task is to rearrange the array elements alternatively i.e first element should be max value, second should be min value, third should be the second max, fourth should be the second min, and so on...Which is a very famous and Routine question asked in Interview. The question is from the Topics Data structure. A full easy concept in Hindi. This is Question is asked in Many companies like Google, Amazon, Oyo Rooms, Paytm, Samsung, Adobe, etc..
We also Provide courses on Competitive Programming and Data structure. Please see our Full Playlist on our Channel.
----------------------------------------------------------------------------------------
► Homework Question: practice.geeksforgeeks.org/pr...
----------------------------------------------------------------------------------------
► Rearrange Array Alternately: practice.geeksforgeeks.org/pr...
► PDF of Rearrange Array Alternately: github.com/Prince-1501/Hello_...
► CODE of Rearrange Array Alternately: github.com/Prince-1501/Hello_...
----------------------------------------------------------------------------------------
*Follow me *
LinkedIn► / iamprince
Facebook► / helloworldofficials
Instagram► / helloworldbyprince
Twitter► / prince_king_
----------------------------------------------------------------------------------------
►Our Playlists on:-
►Competitive Programming : • How to start Competiti...
►C++ Full Course : • L-01 || Introduction a...
►Algorithms : • L-01 || Prefix Sum Arr...
►Data Structure : • Data Structures with C...
------------------------------------------------------------------------
Our Students Contacts Form:-
Form link: docs.google.com/forms/d/e/1FA...
------------------------------------------------------------------------
#interview_preparation #geeksforgeeks #Hindi
7:25. ...phool paate wala division 😝😂👌 leaning ke saath entertaining hae yeh video 👍
Awesome explanation! Please continue LeetCode Series sir. Cover atleast 600 questions so that we get prepared for Placements! One video daily sir:)
mera v yahi thought hai ekdum
great I solved that practise question you gave, you explained the formula very well, this is what I wanted great job.
Thanks for watching ❤️
Keep sharing with your friends
Excelent explanation buddy......have been thinking for like 1 day, never thought of this approach, solved it using O(n) extra space. But your explanation is the best. Keep making these types of videos. You just earned a subscriber. Thankyou.
Very welcome! Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
beautifully explained, awesome
some key points
any no%m = [0 to m-1]
min elements are at odd postitions [1,3,,,,]
max elements are at even postitions [0,2,,,,]
we're basically storing 2 no's with a single no: using basic concept: dividend = divisor * quotient + remainder
using modulo in each operation will give us older number(As that number may have modified already) (around 14:00 to 16:00 in video)
Jalwa Gajab Ka tha sirji....💯💯🙌🙌
Bayya make 1 videos per day.... please...main thing is to group these videos according to their concepts (playlist)...very help full...
I will definitely try to make one vidoe ❤️
Very helpful video ...I like it 😊
Gajab concept bhaiya..maja aa gaya
In simple english --> By adding arr[i] every time, you are making sure that whenever you will take a % with maximum element, you will always get the original array in return, and by multiplying with modulo of alternate maximum and minimum values you are making sure that when you divide it by maximum element you will always get the new alternate array back
Beautifully explained
I've watched many videos regarding this problem and this video has the best explanation. You were not rushing to teach the concept and made even the tiniest bit of things clear. Your new subscriber. Keep it up!
You're welcome! Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
@@HelloWorldbyprince cost to free but itna awsome concept share karne me jalan to hoti hai na bhaiya 🤪🤪🤪🤪🤪
By the end of 2021 you might have around 1 million subs...
Bhai please... Sare graph, trees linked list jo bhi sb important questions hote h.. Jitne bhi interview k lie sare questions jo usually puchte h .. Please complete all of these if possible
Array , string sab kuch sorting A to Z ...
*I recentlt watched a video of your on linked list. And after watching that video i realised that you are the person i am looking for previous 3 months on youtube...
Please complete ASAP..
If possible come live and exoplain code .. Please please please try to make as much as videos you can on a single day...
Thanks a lot for these wonderful response ❤️
I don't know I reach 1M or not ?
But right now subscribers like you are the need of Hello World
Thanks a lot
I will definitely make videos and each and every topics
And I will try ASAP
Your explanation is very good!!
Better than others explaination its good but still filling like zajbat badal gye
Thanks , Hahahhaah
this guy trying this best to teach the concept. respect
Thanks Pavan for support
Bhai tera padhane ka tarika mst h 👍👍👍
dil se thanks bhai
Beautiful Explanation! bhaiya you give each and every thing with logic and all the Concepts with Reason which is not Present anywhere else. Thanks a Lot bhaiya. Generally I do not Comment but Today I couldn't Refrain myself.
So nice of you
wow loved it, but there was lag in audio... though keep up the good work
One of the best problem solving video.... great job bhaiyaa.
Keep learning buddy 😊
Best Explanation !! Thanks a lot 🙌
thanks nayan
Thanks sir you made it very easy to understand this concept. Please Continue uploading questions sir. Fortunate to discover this explanation series.
Thank you, I will
Jajakallahu khair bhaya ..
Perfect video like karke iss video ke top me push kardo bhailog.
keep learning buddy and be consistent and share my channel with your college groups that helps me a lot
good explanation
Really Great intuition!🙏🙏
Thanks a lot buddy
such a good explanation. Thanks bhaiya.👍🏻👍🏻
Thanks buddy ❤️
Buddy, i never commented on anyone's video.. but your explaination,, literally made me do so.. no words to explain.. just wanna say, thanks buddy.. fabulous work🙌🙌
Waoo I feel lucky today 😎😎
Sir, please make a video on how to find time complexity of any algorithm. I'm beginner in ds/algo
Yeah sure
Great explaination
Great explanation 👍. Please explain in English
Awesome bruh!
Very Nice
Thanks
16:53 confusion start 😂 ... Confused between mod and divide , itna part delete kar dete
yehi toh genuinity h bande ke !!
I've just started DSA and a friend suggested me this video. Turned out to be really helpful !!!
Thanks brother
I hope you also spread my channel and someone else also send me message like u 🙂🙂
Thanks
Keep learning buddy
Bhaiya u r awesome. No more words for u
thanks a lot Jaikishan
keep learning buddy and be consistent and share my channel with your college groups that helps me a lot
Thank you x 100
Welcome x 1000000
nicely explained such a complex approach
Keep learning and sharing buddy ❤️
ncy explaination!!!!!
finally found the best explanation
for this question
Glad it helped! Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
Thx bhaiya for this ❤ lecture
thanks a lot
Thank You So Much!.
your welcome buddy
Sir, please tell me from where do I build this kind of logic during the placement coding interview. It doesn't click directly after seeing the question and we have a time limit to finish the question. How to improve the logic building part??
Trust me 😀.... One simple RULE ...only practice ....
Don't think like that... Ye questions agar interview me aata to first time me mere se nahi hota ...
Think like that ....ki bahut saraa question practice karne ke baad ye logic to generate ho hi jata
nice explanation
Very good explanation sir
Keep watching
🔥🔥
Thanks brother 😊
great explanation
Glad it was helpful!
bro, I have participated in hacktoberfest 2020, please can you make a video on that , as to how make quality pull request and win the challenge
its very simple bro just write or copy paste any good programs and make pull requests try to make 2 or 3 extra and you are done then after around 7 months raom outside with hacktoberfest T shirt
Bhaut badiya sir
Thanks a ton yaar
Thank you 💘
Any time!
We can do it in O(N^2) by reversing array starting from ith index to last index
Amazing!
Thank you! Cheers!
Thanks bro
How to deal with, when we have -ve numbers ?
Highly conceptual...
Thanks buddy
@@HelloWorldbyprince ghanta mera lele...
sir please tell the solution order will be maintain
Matlab ?
@@HelloWorldbyprince in gfg there was a question to rearrange the array where order should be maintained in question 5 in arrangement section of array
bhaiya agar app blackboard pe smjate too clearly jhda hotii ppt pe nhi ho rhiiiiiiiiii
😊
Great explanation.
keep learning buddy and be consistent and share my channel with your college groups that helps me a lot
@@HelloWorldbyprince Sure. :)
arr[k]=(arr[j]%maxx)*maxx+arr[k], sir in statement (arr[j]%maxx) we are getting same arr[j] value, then why is this showing error when i am direct putting arr[j] ?
nicely explaination
Thanks Yash
Nice logic sirrr❤❤❤❤❤❤
3:17 roasted me so bad i was trying to swap 😂😂
It happens 😂😂
Thanks bro
Welcome
2.06 ultimately nahi hua hoga hits hard
👍👍👍❤❤
🔥🔥
Gjb sir
yeahh thanks bro
class Solution:
def rearrangeEvenOdd(self, head):
#code here
if head==None:
return head
temp=head
x=head
y=head.next
t=head
while temp.next!=None:
ptemp=temp
temp=temp.next
ptemp.next=temp.next
while x.next!=None:
x=x.next
x.next=y
return t
#reply if it is wrong
#like if it is correct
Bhai jahan khud ko yaad naa aaye wo part cut kar diya karo!
bachche darr jaayenge ki kitna tough questiom hai
I got stuck in this part bhaiya like you are sayin Index (n-1) = 6*7 kaise hua
Explanation was too good but logic samjna ma ek do din laag jayenga😂
Nice video sir
home work is done Sir in O(1) Space complexity but I'm unable to digest this Method.
Try
this is the best youtube channel I found in 2020
if u teach in english itwill be very grateful
sure i will try my best
bhaiya Phd wale professors aapke saamne paani bharenge ..pura concept smjh aaa jata hai ...thanks bhaiya
🤣🤣
i don't know how this code work for the same problem but please tell me this
#User function Template for python3
class Solution:
##Complete this function
#Function to rearrange the array elements alternately.
def rearrange(self,arr, n):
##Your code here
i=0
j=n-1
temp=[]
if n==1:
return arr
elif n%2!=0:
while i
There must be some internal Issue, it is not of O(1) Space
this code is not working for negative integers in array
How the formulation created.
Just by analysing the data
but for negative values it will not work
i did not understant why we are doing arr[i]%maxi , why not take only arr[i]
bro i guess u must have to do dry of the code
baki bhaiya thankuuuuu
Thanks a lot jasmeen ❤️
aisa lag raha he 5th standard me aa gaya
bhai apne mai hi krlo video yu daale ho
😇
If to understand the logic, i am taking such long, how can i create my own logic?😂 whoever has solved this problem in his first attempt without any hint must be genius.
its beginning and you are going good
ping++
do your revision first then teach no dry run wt was that
Bhaiya please directly explaination bataya kro , bakiki baate mt bataya kro
Taaki tm chhap ke count bdha sko
Bro dont give wrong content