Rearrange Array so that Arr[i] becomes Arr[Arr[i]] with O(1) extra space

Поділитися
Вставка
  • Опубліковано 29 вер 2024
  • Rearrange a given array so that Arr[i] becomes Arr[Arr[i]] with O(1) extra space.
    Example:
    Input : [1, 0]
    Return : [0, 1]
    Let's say N = size of the array. Then, the following holds true :
    All elements in the array are in the range [0, N-1]
    N * N does not overflow for a signed integer

КОМЕНТАРІ • 43

  • @neerajgarg9096
    @neerajgarg9096 2 роки тому +4

    Hey Alisha Great Explanation but have one doubt that its like we have to mug up this approach so if i try to solve this after 1 week i definitely forget it so how to remember these type of questions?

  • @AvinashKumar-vv4vd
    @AvinashKumar-vv4vd 2 роки тому +1

    Really good explanation 👍

  • @reshmah1497
    @reshmah1497 2 роки тому

    Useful video...explanation is understandable

  • @dheerajmct
    @dheerajmct Рік тому

    You r simply the best

  • @rahultomar8349
    @rahultomar8349 2 роки тому

    thanks and keep making the such awesome videos.

  • @asad_mirza
    @asad_mirza 2 роки тому

    Muskuraiye ...you have a new subscriber 😁

  • @ceb-rj4qw
    @ceb-rj4qw Рік тому

    SUper

  • @amberraghuwanshi859
    @amberraghuwanshi859 Рік тому

    WOW

  • @AmanRaj-ux8cw
    @AmanRaj-ux8cw 2 роки тому +4

    I'm searching a good video for array explanation and I really find good content. Thank you so much for sharing this. 😀

  • @billgatesbisht6665
    @billgatesbisht6665 8 місяців тому

    new approach .... SC O(1)... TC O(n) ....
    void arrange(long long arr[], int n) {
    for(int i=0;i

  • @piyushsrivastava5883
    @piyushsrivastava5883 7 місяців тому

    for the people why she is taking n as parameter of dividing or taking modulo because as the question suggested the element is less than n so the number should be in between .might clear

  • @SachinNagareiGTB
    @SachinNagareiGTB 7 місяців тому

    can you give me explanation on this= sum(arr,n-1)+arr[n-1],what exactly going on here

  • @siddharthb2226
    @siddharthb2226 5 місяців тому

    Awesome explanation! I have started solving InterviewBit problems, hopefully u have ciovered them all

  • @HarendraKumar-yr4gt
    @HarendraKumar-yr4gt 3 роки тому +2

    Best explanation ever, thanks, please keep making such awesome videos! learning a lot

  • @avishjain5799
    @avishjain5799 2 роки тому +2

    What is the intuition behind this approach.

  • @rohankumarshah5679
    @rohankumarshah5679 2 роки тому +1

    i thought why there's need to put modulo n in arr[arr[i]]%n *n since all the numbers in arr are less than n
    but
    now i realized as we multiply no's are changing at arr[i] so we have to first modulo n then just do multiply with n

  • @suyashpurwar631
    @suyashpurwar631 Рік тому

    Should have focused on the mathematical intuition

  • @learncreative4732
    @learncreative4732 Рік тому

    How to get logic these type of question 😢

  • @rashedin6356
    @rashedin6356 9 місяців тому

    approach should be cyclic sort

  • @RajeshwariGorla-jk1pr
    @RajeshwariGorla-jk1pr 6 місяців тому

    how to convert into long??

  • @deepakgaroda975
    @deepakgaroda975 Рік тому +1

    Your way of explaining is awesome...

  • @harshvardhan7161
    @harshvardhan7161 Рік тому

    constant space**

  • @muskancreativity7
    @muskancreativity7 2 роки тому +1

    Best explanation 💜

  • @janaSdj
    @janaSdj Рік тому

    wowwww....

  • @dspeaks9756
    @dspeaks9756 2 роки тому

    Thanks Alisha....what an easy explanation.....this gave me learning without wasting much time

  • @anshikaaa3716
    @anshikaaa3716 Рік тому

    Great explanation! Immediately subscribed :)

  • @AmarjeetKumar-to9ub
    @AmarjeetKumar-to9ub Рік тому +1

    🔥++

  • @venkatanagaprathapyelugula7738
    @venkatanagaprathapyelugula7738 2 роки тому

    Thanks for explanation...Thanks my dear sister.

  • @niranjanaware5930
    @niranjanaware5930 Рік тому

    plz continue creating such great sols..thanks

  • @satyareddy8671
    @satyareddy8671 Рік тому

    I love the way you explained mam.

  • @harshitsharma1880
    @harshitsharma1880 Рік тому

    clean and clear explanation thanks for good content..

  • @milindbadekar3503
    @milindbadekar3503 2 роки тому

    Thank u.Keep working .Dont stop.

  • @jashwanthpeddisetty3264
    @jashwanthpeddisetty3264 Рік тому

    awesome explanation

  • @thegreekgoat98
    @thegreekgoat98 Рік тому

    Nice explanation

  • @ShivamGupta-po7rg
    @ShivamGupta-po7rg 2 роки тому

    thank you ; )

  • @raj_kundalia
    @raj_kundalia 2 роки тому

    thank you

  • @rajaspaunikar9695
    @rajaspaunikar9695 2 роки тому

    ALISHA MAHARANI KI JAI!!!

  • @SANCHITJAIN_
    @SANCHITJAIN_ 2 роки тому

    great explanation...loved it !!

  • @SatishKanaujiyaeb
    @SatishKanaujiyaeb Рік тому

    This question is like hit or miss. If you hit, you will solve this otherwise (:-

  • @066lakshmipriya3
    @066lakshmipriya3 2 роки тому

    Why should we take %n before multiplying with n?

    • @rohankumarshah5679
      @rohankumarshah5679 2 роки тому

      initially all the numbers in array are 0 to n-1 ie less than n so no need to modulo, right ??
      just do arr[i] = arr[arr[i]] * n;
      but,
      when we have done one operation what if we are accessing the number at arr[i] that was earlier multiplied with n by us,
      therefore we need to initially modulo n then multiply with n.