Created
February 5, 2025 04:10
-
-
Save mridubhatnagar/cf41cc77786f9bf45825c05b1933c9f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"slices" | |
) | |
func main() { | |
var totalTests int | |
fmt.Scanf("%d", &totalTests) | |
var length int | |
var elementA int | |
var elementB int | |
var a = [] int{} | |
var b = [] int{} | |
// var sumArray = [] int{} | |
// var sum int = 0 | |
// var ctr int = 0 | |
var first int | |
var second int | |
var third int | |
var firstA int | |
var secondA int | |
var firstB int | |
var secondB int | |
// var temp int | |
for i:=1;i<=totalTests;i++ { | |
fmt.Scanf("%d", &length) | |
// fmt.Printf("%d\n", length) | |
a = [] int{} | |
b = [] int{} | |
for j:=0;j<length;j++ { | |
if j != length - 1 { | |
fmt.Scanf("%d", &elementA) | |
} else { | |
fmt.Scanf("%d\n", &elementA) | |
} | |
a = append(a, elementA) | |
} | |
for k:=0; k<length; k++ { | |
if k != length - 1 { | |
fmt.Scanf("%d", &elementB) | |
} else { | |
fmt.Scanf("%d\n", &elementB) | |
} | |
b = append(b, elementB) | |
} | |
// fmt.Println(a) | |
// fmt.Println(b) | |
slices.Sort(a) | |
slices.Sort(b) | |
// 3 distinct | |
second = 0 | |
third = 0 | |
for i:=1;i<=length-2; i++ { | |
first = a[0] | |
if a[i] != first && second == 0{ | |
second = a[i] | |
} else if a[i] != second && a[i] != first { | |
third = a[i] | |
} | |
} | |
// fmt.Println("=======") | |
// fmt.Printf("%d %d %d\n", first, second, third) | |
if first != 0 && second != 0 && third != 0 { | |
if first != second && second != third && third != first { | |
fmt.Println("YES") | |
continue | |
} | |
} | |
// 2 distinct in array A and B | |
firstA = 0 | |
secondA = 0 | |
for i:=1; i<=length-2;i++ { | |
firstA = a[0] | |
if firstA != a[i] { | |
secondA = a[i] | |
break | |
} | |
} | |
// fmt.Printf("%d %d\n", firstA, secondA) | |
firstB = 0 | |
secondB = 0 | |
for i:=1;i<=length-2;i++ { | |
firstB = b[0] | |
if firstB != b[i] { | |
secondB = b[i] | |
break | |
} | |
} | |
// fmt.Printf("%d %d\n", firstB, secondB) | |
if firstA != 0 && secondA != 0 && firstB != 0 && secondB != 0 { | |
fmt.Println("YES") | |
continue | |
} else { | |
fmt.Println("NO") | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment