All Tracks Algorithms String Algorithms String Searching Problem

Sartaj's Challenge
Tag(s):

Easy, KMP, String Algorithms

Problem
Editorial
Analytics

Sartaj Singh is a troubled police inspector in Mumbai police, living in sleeping pills and loathes his job which is full of corrupted officers. One day he receives an anonymous call from Ganesh Gaitonde, a notorious crime lord who has been missing for 16 years. Gaitonde tells Singh to save the city in 25 days which leads to a chain of events. In order to save Mumbai and reach the next clue, Sartaj has to solve the question given to him by Gaitonde. As Sartaj is not in the right state of mind due to his troubled lifestyle, he asks you for help. 

Gaitonde gives him two arrays A and B of same length N
He can perform the following type of operations:

1. He can rotate the whole array A.
2. He can rotate the elements of A which are only at the odd positions.
3. He can rotate the elements of A which are only at the even positions.

He can perform these operations as many time as he wants.

Help Sartaj to tell whether array B can be generated by array A after applying given operations on A.

Note: N is obliged to be evenly divisible by 2.

Input format :

  • First line: a single integer \(T \) denoting the number of test cases.
  • The first line of each test cases contains a single integer \(N \) denoting the size of the array.
  • The second line of each test cases contains \(N\) space separated integers denoting the array A.
  • The second line of each test cases contains \(N\) space separated integers denoting the array B.

Output format :

  • For each test cases print  "Yes" if Array B can be generated by array A after applying given operations on A otherwise "No" in New Line (without quotes).

Constraints :

  • \(1 \le T \le 10\)
  • \(1 \le N \le 100000\)
  • \(1 \le A[i] \le 10^{9}\)

Explanation :

SAMPLE INPUT
2
4
4 4 4 4
4 4 4 4
4
1 2 3 4
3 4 5 2
SAMPLE OUTPUT
Yes
No
Explanation

TestCase 1: A and B is the same.

TestCase 2: There is no possible way to convert A into B.

Time Limit: 1,0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

NIT Surat

Challenge Name

EPIPHANY 8.0

OTHER PROBLEMS OF THIS CHALLENGE
Уведомления
View All Notifications

?