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
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?
Yes same
Really good explanation 👍
Useful video...explanation is understandable
You r simply the best
thanks and keep making the such awesome videos.
Muskuraiye ...you have a new subscriber 😁
SUper
WOW
I'm searching a good video for array explanation and I really find good content. Thank you so much for sharing this. 😀
new approach .... SC O(1)... TC O(n) ....
void arrange(long long arr[], int n) {
for(int i=0;i
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
can you give me explanation on this= sum(arr,n-1)+arr[n-1],what exactly going on here
Awesome explanation! I have started solving InterviewBit problems, hopefully u have ciovered them all
Best explanation ever, thanks, please keep making such awesome videos! learning a lot
What is the intuition behind this approach.
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
Should have focused on the mathematical intuition
How to get logic these type of question 😢
approach should be cyclic sort
how to convert into long??
Your way of explaining is awesome...
constant space**
Best explanation 💜
wowwww....
Thanks Alisha....what an easy explanation.....this gave me learning without wasting much time
Great explanation! Immediately subscribed :)
🔥++
Thanks for explanation...Thanks my dear sister.
plz continue creating such great sols..thanks
I love the way you explained mam.
clean and clear explanation thanks for good content..
Thank u.Keep working .Dont stop.
awesome explanation
Nice explanation
thank you ; )
thank you
ALISHA MAHARANI KI JAI!!!
great explanation...loved it !!
This question is like hit or miss. If you hit, you will solve this otherwise (:-
Why should we take %n before multiplying with n?
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.