We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I did it in O(n) by storing the index of the elements in an array.Initialize the index array with -1 and then store the index of each element.take the ith element and check whether the M-arr[i]'s index is>=0(means its present in the array) and the index!=i(to avoid repetation).It works for all test cases.
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
I did it in O(n) by storing the index of the elements in an array.Initialize the index array with -1 and then store the index of each element.take the ith element and check whether the M-arr[i]'s index is>=0(means its present in the array) and the index!=i(to avoid repetation).It works for all test cases.