Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
We are given array of n integers and Q queries , in each query we are given 2 ranges, ie
The queries are given as "a b c d" where a and b are the left and right end point of the first sub-array and c and d are the left and right end point of the second sub-array.
we need to find whether two subarrays are equal or not?

Subarray are equal if their size is equal and after sorting it all the values at all indices matches with each other ?
Number of queries <= 10^5
Size of array <= 10^5

Example:
TestCase:
6 3 // n and q
1 3 4 2 3 4 // array elements
1 3 4 6 // queries
1 2 5 6
3 5 2 4

Output:
YES
NO
YES


What I have tried:

I have tried with many things but its giving me TLE ans its complexity is not good
Posted
Updated 8-Jun-17 12:23pm

1 solution

Do yourself a favor and stop doing those challenges.
All what you learn is that you are unable to complete them fast enough.
To compete on those challenges, you need to learn advanced algorithms (and understand them), and it is not just a few, there are tens of them, and you need to learn the art of combining them to get an optimum solution.
As you learn algorithms, you will see that you also need to master data structures.
All those fit in books and there is no way we can teach them to you in the frame of this forum.
Quote:
I have tried with many things but its giving me TLE ans its complexity is not good

You have shown us nothing of your work, you did not even asked a question.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900