• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
June 17, 2022 |14.4K Views

Relative Sorting | SDE Sheet | Hashing

Description
Discussion

In this video we will see when given two arrays A1[] and A2[], how to sort A1 in such a way that the relative order among the elements will be same as those are in A2. For the elements not present in A2, append them at last in sorted order.

Examples: 
Input: A1[] = {2, 1, 2, 5, 7, 1, 9, 3, 6, 8, 8}
      A2[] = {2, 1, 8, 3}
Output: A1[] = {2, 2, 1, 1, 8, 8, 3, 5, 6, 7, 9}

Check out the video to see how we implement this!!


Practice Problem: https://practice.geeksforgeeks.org/problems/relative-sorting4323/1
Article: https://www.geeksforgeeks.org/sort-array-according-order-defined-another-array/
SDE Sheet: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/