Question: Create a new file called scrambled.c, containing a single function that matches this declaration: int scrambled( unsigned int arr1[], unsigned int arr2[], unsigned int len
- Create a new file called scrambled.c, containing a single function that matches this declaration:
int scrambled( unsigned int arr1[], unsigned int arr2[], unsigned int len );
- Arrays arr1 and arr2 are both of length len, and contain values in the range [0 .. 99] inclusive, only.
- The function scrambled() should return 1 iff arrays arr1 and arr2 contain the same values in any order, or 0 otherwise.
- len can have any unsigned int value, including 0.
- If len is 0 then scrambled() should return 1 (since the arrays have the same - empty - contents).
- You must not change the contents of the arrays.
- Use an algorithm that has run time linear in the array length n. Note that this means you can not sort the arrays since that can not be done in linear time.
Examples of arrays for which scrambled should return 1:
- arr1 = {10,15,20}, arr2 = {10,15,20}
- arr1 = {99}, arr2 = {99}
- arr1 = {1,2,3,4,5}, arr2 = {5,3,4,2,1}
- arr1 = {}, arr2 = {} (i.e. len = 0)
- arr1 = {2,1,3,4,5}, arr2 = {1,2,4,3,5}
Examples of arrays for which scrambled should return 0:
- arr1 = {1,1}, arr2 = {1,2}
- arr1 = {10,15,20}, arr2 = {10,15,21}
- arr1 = {1,2,3,4,5}, arr2 = {5,3,4,2,2}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
