0% found this document useful (0 votes)
51 views2 pages

Video Link: Https://Youtu - Be/Fcbeciotnz4: If The Number in That Position in The Array Is A

The document summarizes rearranging an array to remove duplicates. It shows an original array with duplicates and creates a boolean "used" array to track elements. It searches for the first 4, finds the first unused 5, saves its index, and swaps the 5 with the element in front of the 4. This replaces the duplicate while keeping other elements in order.

Uploaded by

Orlando Alvarez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views2 pages

Video Link: Https://Youtu - Be/Fcbeciotnz4: If The Number in That Position in The Array Is A

The document summarizes rearranging an array to remove duplicates. It shows an original array with duplicates and creates a boolean "used" array to track elements. It searches for the first 4, finds the first unused 5, saves its index, and swaps the 5 with the element in front of the 4. This replaces the duplicate while keeping other elements in order.

Uploaded by

Orlando Alvarez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Video link: ​[Link]

be/fCbECIotNz4
Visual aids used in the exposition

Original array:
nums = [4, 9, 4, 9, 5, 5, 4, 9, 5]

Create auxiliary boolean array to check if the


number has been used (rearranged).

nums = [4, 9, 4, 9, 5, 5, 4, 9, 5]
used = [x, x, x, x, x, x, x, x, x]

Search in the array set by parameter.

if the number in that position in the array is a 4


​ :​

nums = [​4​, 9, 4, 9, 5, 5, 4, 9, 5]
used = [x, x, x, x, x, x, x, x, x]

Look for an ​unused​ five in the array:

nums = [​4​, 9, 4, 9, 5
​ ​, 5, 4, 9, 5]
used = [x, x, x, x, x, x, x, x, x]

Save the position:

auxIndex = the index of the 5 we’re using (index 4, in this case)

nums = [​4​, 9, 4, 9, 5
​ ​, 5, 4, 9, 5]
used = [x, x, x, x, x, x, x, x, x]

*Stops navigating the array*

At the saved position (5’s index), replace the 5 with


the value in front of the 4.

nums = [​4​, ​9​, 4, 9, ​9 ​(u​ sed to be 5​), 5, 4, 9, 5]


used = [x, x, x, x, √, x, x, x, x]
Replace the value in front of the 4 for a 5 and mark
that number as used.

nums = [​4​, ​5​, 4, 9, 9, 5, 4, 9, 5]


used = [x, √, x, x, √, x, x, x, x]

You might also like