Match the Range

IamHot Stamford University Bangl...
Limits 1s, 512 MB

Well, I will not waste your time and go straight to the problem.

You are given an array A of numbers. And some queries. Each query consists of two ranges. You need to find out if those two ranges are similar or not. You are given a function to figure out if two ranges are same or not.

function IsSame(x1, y1, x2, y2)
    Array1 = []
    Array2 = []

    For i = x1 to y1
    end For 

    For i = x2 to y2
    end For 

   NewArray1 = sort the elements inside Array1
   NewArray2 = sort the elements inside Array2

  return (NewArray1 equals NewArray2)
end function


The first line contains two integer N - number of elements in the array and Q - number of queries.
Next line contains N integers denoting the ith element of the array A.

Next there are Q queries with four integers which is described above.

  • 1 ≤ N, Q ≤ 105
  • 1 ≤ A[i] ≤ 105
  • 1 ≤ x1, y1, x2, y2 ≤ N


For each query, use the function given above and if the function returns true value print "Yes" otherwise print "No" without quote .


6 3
1 2 3 1 2 3
1 3 4 6
2 4 3 5
1 2 2 3


Login to submit.


56% Solution Ratio
sakibalaminEarliest, May '19
sakibalaminFastest, 0.0s
Alamin_justLightest, 1.2 MB
Mr_BangladeshShortest, 474B
Toph uses cookies. By continuing you agree to our Cookie Policy.