package main
import (
"fmt"
)
func isSubset(arr1 []int, arr2 []int) bool {
// Create a map to store elements of arr1
elements := make(map[int]bool)
// Populate the map with elements from arr1
for _, value := range arr1 {
elements[value] = true
}
// Check if all elements of arr2 exist in the map
for _, value := range arr2 {
if !elements[value] {
return false // Element not found, arr2 is not a subset
}
}
return true // All elements found, arr2 is a subset
}
func main() {
arr1 := []int{5, 1, 8, 12, 40, 7, 9, 100}
arr2 := []int{8, 40, 9, 1}
if isSubset(arr1, arr2) {
fmt.Println("Yes, arr2 is a subset of arr1")
} else {
fmt.Println("No, arr2 is not a subset of arr1")
}
}
/*
run:
Yes, arr2 is a subset of arr1
*/