Rearrange Array Alternately in O(1) space complexity and O(N) Time Complexity Geeksforgeeks Solution

Sdílet
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

Komentáře • 148

  • @bhupeshpattanaik7150
    @bhupeshpattanaik7150 Před 3 lety +10

    7:25. ...phool paate wala division 😝😂👌 leaning ke saath entertaining hae yeh video 👍

  • @otismilburn9018
    @otismilburn9018 Před 2 lety +15

    Awesome explanation! Please continue LeetCode Series sir. Cover atleast 600 questions so that we get prepared for Placements! One video daily sir:)

  • @sajalsangal1436
    @sajalsangal1436 Před 3 lety +4

    great I solved that practise question you gave, you explained the formula very well, this is what I wanted great job.

  • @theroastingtoaster8542
    @theroastingtoaster8542 Před 2 lety +3

    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.

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před rokem

      Very welcome! Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @divy04
    @divy04 Před měsícem

    beautifully explained, awesome

  • @AnandSharma-lt8wq
    @AnandSharma-lt8wq Před 3 lety +1

    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)

  • @ankushladani496
    @ankushladani496 Před rokem

    Jalwa Gajab Ka tha sirji....💯💯🙌🙌

  • @rafiqn2675
    @rafiqn2675 Před 3 lety +5

    Bayya make 1 videos per day.... please...main thing is to group these videos according to their concepts (playlist)...very help full...

  • @saurabhvishwakarma2320
    @saurabhvishwakarma2320 Před 3 lety +2

    Very helpful video ...I like it 😊

  • @VivekKumar-ui1ro
    @VivekKumar-ui1ro Před rokem

    Gajab concept bhaiya..maja aa gaya

  • @musafirgauravv
    @musafirgauravv Před 5 měsíci

    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

  • @alexmercer5870
    @alexmercer5870 Před 3 lety +1

    Beautifully explained

  • @sahilverma3976
    @sahilverma3976 Před 2 lety +6

    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!

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před rokem +1

      You're welcome! Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

    • @ahn360
      @ahn360 Před rokem

      @@HelloWorldbyprince cost to free but itna awsome concept share karne me jalan to hoti hai na bhaiya 🤪🤪🤪🤪🤪

  • @shashanksabharwal8591
    @shashanksabharwal8591 Před 3 lety +6

    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...

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 3 lety +6

      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

  • @pranavkochhar9352
    @pranavkochhar9352 Před 3 lety

    Your explanation is very good!!

  • @Knowledgeduniya1432
    @Knowledgeduniya1432 Před rokem +1

    Better than others explaination its good but still filling like zajbat badal gye

  • @pavankumar-lv4ne
    @pavankumar-lv4ne Před 2 lety +1

    this guy trying this best to teach the concept. respect

  • @ROHITRAJ-bc7nq
    @ROHITRAJ-bc7nq Před 2 lety +1

    Bhai tera padhane ka tarika mst h 👍👍👍

  • @ayushanand4530
    @ayushanand4530 Před rokem +1

    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.

  • @samridhup
    @samridhup Před 3 lety +4

    wow loved it, but there was lag in audio... though keep up the good work

  • @ishitaroy2238
    @ishitaroy2238 Před 2 lety +1

    One of the best problem solving video.... great job bhaiyaa.

  • @nayankhuman1043
    @nayankhuman1043 Před rokem

    Best Explanation !! Thanks a lot 🙌

  • @yagizegemen7303
    @yagizegemen7303 Před rokem

    Thanks sir you made it very easy to understand this concept. Please Continue uploading questions sir. Fortunate to discover this explanation series.

  • @shaiksabiha5796
    @shaiksabiha5796 Před rokem

    Jajakallahu khair bhaya ..

  • @alphazero0
    @alphazero0 Před 2 lety +1

    Perfect video like karke iss video ke top me push kardo bhailog.

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety

      keep learning buddy and be consistent and share my channel with your college groups that helps me a lot

  • @nayasavlog1816
    @nayasavlog1816 Před 3 lety +2

    good explanation

  • @anotherstranger3968
    @anotherstranger3968 Před 3 lety +1

    Really Great intuition!🙏🙏

  • @harsimran.27
    @harsimran.27 Před 3 lety +1

    such a good explanation. Thanks bhaiya.👍🏻👍🏻

  • @RakeshKumar-pi8wh
    @RakeshKumar-pi8wh Před 2 lety +3

    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🙌🙌

  • @akashkhandelwal-altruistic5363

    Sir, please make a video on how to find time complexity of any algorithm. I'm beginner in ds/algo

  • @SunnyKumar-ud9gp
    @SunnyKumar-ud9gp Před 3 lety

    Great explaination

  • @vinothkannans1910
    @vinothkannans1910 Před 3 lety +1

    Great explanation 👍. Please explain in English

  • @mcaddit6802
    @mcaddit6802 Před 3 lety

    Awesome bruh!

  • @sudhakarkumar3039
    @sudhakarkumar3039 Před rokem +1

    Very Nice

  • @bhupeshpattanaik7150
    @bhupeshpattanaik7150 Před 3 lety +7

    16:53 confusion start 😂 ... Confused between mod and divide , itna part delete kar dete

  • @trigunadityapnd
    @trigunadityapnd Před 2 lety +1

    I've just started DSA and a friend suggested me this video. Turned out to be really helpful !!!

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety +1

      Thanks brother
      I hope you also spread my channel and someone else also send me message like u 🙂🙂

  • @cr7johnChan
    @cr7johnChan Před 2 lety +1

    Thanks

  • @JaikishanJaikumar
    @JaikishanJaikumar Před 2 lety +1

    Bhaiya u r awesome. No more words for u

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety +1

      thanks a lot Jaikishan
      keep learning buddy and be consistent and share my channel with your college groups that helps me a lot

  • @sushantpandey2127
    @sushantpandey2127 Před 2 lety +1

    Thank you x 100

  • @Socrates225
    @Socrates225 Před 3 lety +1

    nicely explained such a complex approach

  • @mohammedayan7157
    @mohammedayan7157 Před rokem

    ncy explaination!!!!!

  • @vikas5840
    @vikas5840 Před rokem

    finally found the best explanation
    for this question

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před rokem

      Glad it helped! Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @sudhadevi6692
    @sudhadevi6692 Před 11 měsíci

    Thx bhaiya for this ❤ lecture

  • @mohammedwaseem8599
    @mohammedwaseem8599 Před 3 lety

    Thank You So Much!.

  • @asthadubey6571
    @asthadubey6571 Před 3 lety +1

    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??

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 3 lety +6

      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

  • @Sonsourav
    @Sonsourav Před 3 lety

    nice explanation

  • @sidharthreddyarutla7483
    @sidharthreddyarutla7483 Před 2 lety +1

    Very good explanation sir

  • @shikhar2k01
    @shikhar2k01 Před 2 lety +1

    🔥🔥

  • @amanmahajan1666
    @amanmahajan1666 Před 2 lety

    great explanation

  • @chidambarjoshi3470
    @chidambarjoshi3470 Před 3 lety +2

    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

    • @RiteshYadav-rc1np
      @RiteshYadav-rc1np Před 3 lety

      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

  • @ProgrammingWithProject

    Bhaut badiya sir

  • @coderbhai4958
    @coderbhai4958 Před 2 lety +1

    Thank you 💘

  • @paraskumar693
    @paraskumar693 Před 2 lety

    We can do it in O(N^2) by reversing array starting from ith index to last index

  • @dhairyataneja3211
    @dhairyataneja3211 Před rokem

    Amazing!

  • @InvincibleMan99
    @InvincibleMan99 Před 2 lety

    Thanks bro
    How to deal with, when we have -ve numbers ?

  • @vishalshukla3299
    @vishalshukla3299 Před 3 lety +1

    Highly conceptual...

  • @unnatigupta6647
    @unnatigupta6647 Před 3 lety +2

    sir please tell the solution order will be maintain

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 3 lety

      Matlab ?

    • @unnatigupta6647
      @unnatigupta6647 Před 3 lety

      @@HelloWorldbyprince in gfg there was a question to rearrange the array where order should be maintained in question 5 in arrangement section of array

  • @jasmeenkaur6001
    @jasmeenkaur6001 Před 3 lety +2

    bhaiya agar app blackboard pe smjate too clearly jhda hotii ppt pe nhi ho rhiiiiiiiiii

  • @harshalgarg1149
    @harshalgarg1149 Před 2 lety

    Great explanation.

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety +1

      keep learning buddy and be consistent and share my channel with your college groups that helps me a lot

    • @harshalgarg1149
      @harshalgarg1149 Před 2 lety

      @@HelloWorldbyprince Sure. :)

  • @succeedwithuttam2271
    @succeedwithuttam2271 Před 3 lety

    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] ?

  • @yashgoswami9227
    @yashgoswami9227 Před 3 lety

    nicely explaination

  • @mayankgarg4157
    @mayankgarg4157 Před 3 lety +2

    Nice logic sirrr❤❤❤❤❤❤

  • @division-gaming
    @division-gaming Před 2 lety +1

    3:17 roasted me so bad i was trying to swap 😂😂

  • @adityatayal3147
    @adityatayal3147 Před 3 lety

    Thanks bro

  • @VaibhavSutar-xm3cn
    @VaibhavSutar-xm3cn Před měsícem

    2.06 ultimately nahi hua hoga hits hard

  • @mohdyasir5421
    @mohdyasir5421 Před 2 lety

    👍👍👍❤❤

  • @mohdyasir5421
    @mohdyasir5421 Před 2 lety

    Gjb sir

  • @chandrashekharpatil6332

    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

  • @davidsharma9662
    @davidsharma9662 Před 5 měsíci

    Bhai jahan khud ko yaad naa aaye wo part cut kar diya karo!
    bachche darr jaayenge ki kitna tough questiom hai

  • @aryamansingha9984
    @aryamansingha9984 Před rokem

    I got stuck in this part bhaiya like you are sayin Index (n-1) = 6*7 kaise hua

  • @330_atharvashirgave8
    @330_atharvashirgave8 Před 2 lety

    Explanation was too good but logic samjna ma ek do din laag jayenga😂

  • @shubhampatel6325
    @shubhampatel6325 Před 3 lety +2

    Nice video sir

  • @UnKnown-id7ih
    @UnKnown-id7ih Před 2 lety

    home work is done Sir in O(1) Space complexity but I'm unable to digest this Method.

  • @pritamsarkar3371
    @pritamsarkar3371 Před 3 lety

    this is the best youtube channel I found in 2020

  • @kothapalliavinashkumar8699

    if u teach in english itwill be very grateful

  • @engineer966
    @engineer966 Před 3 lety +1

    bhaiya Phd wale professors aapke saamne paani bharenge ..pura concept smjh aaa jata hai ...thanks bhaiya

  • @nikhilchaurasiya5156
    @nikhilchaurasiya5156 Před 3 lety

    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

  • @1piecegaming622
    @1piecegaming622 Před 3 lety

    this code is not working for negative integers in array

  • @rabindrakumar949
    @rabindrakumar949 Před 3 lety +1

    How the formulation created.

  • @ahmedanwer1767
    @ahmedanwer1767 Před rokem

    but for negative values it will not work

  • @sidharthdhiman4522
    @sidharthdhiman4522 Před rokem

    i did not understant why we are doing arr[i]%maxi , why not take only arr[i]

  • @jasmeenkaur6001
    @jasmeenkaur6001 Před 3 lety

    baki bhaiya thankuuuuu

  • @VaibhavSutar-xm3cn
    @VaibhavSutar-xm3cn Před měsícem

    aisa lag raha he 5th standard me aa gaya

  • @anandparashar4589
    @anandparashar4589 Před 10 měsíci +1

    bhai apne mai hi krlo video yu daale ho

  • @gamingcircus2637
    @gamingcircus2637 Před 2 lety

    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.

  • @user-zh8rp5xu9o
    @user-zh8rp5xu9o Před rokem

    ping++

  • @Anuj-vf7bg
    @Anuj-vf7bg Před 6 měsíci

    do your revision first then teach no dry run wt was that

  • @inspiredomkar1239
    @inspiredomkar1239 Před 10 měsíci

    Bhaiya please directly explaination bataya kro , bakiki baate mt bataya kro

    • @Rouui9
      @Rouui9 Před 5 měsíci

      Taaki tm chhap ke count bdha sko

  • @technical3199
    @technical3199 Před 2 lety

    Bro dont give wrong content