SRTCHK - Editorial

Problem Link - Sort Checker Practice Problem in Jump from 2* to 3*

Problem Statement:

Given two arrays A and B of size n, you need to determine if array B is the sorted version of array A. The task is to print “yes” if B matches the sorted order of A and “no” otherwise.

Approach:

Sort array A to obtain its sorted version, A_{sorted}. Compare A_{sorted} with B. If they match, print “yes”; otherwise, print “no”. Use inbuilt sort function for sorting.

Complexity:

  • Time Complexity: Sorting A takes O(n log n), and comparing A_{sorted} with B takes O(n).
  • Space Complexity: O(1) No extra space used.