Kotlin | BFS
IntuitionPassed first try. :) See comment at top for my thought process.Complexity

Time complexity:
O(n2+m2+e+f) To create the maps it was necessary to iterate
# Intuition
Passed first try. :) See comment at top for my thought process.

# Complexity
- Time complexity:
$$O(n^2 + m^2 + e + f)$$ To create the maps it was necessary to iterate through each of the adjacency lists, so this would be equal to the number of edges in each graph (let's call them e and f), then do bfs with a maximum depth of k, but potentially all nodes are within k hops away, so this would be n^2 for each of the maps.

- Space complexity:
$$O(n + m + max(e, f))$$ Created graphs from the adjacency lists, store a level in the graph during bfs

# Code
```kotlin []
class Solution {
    fun maxTargetNodes(edges1: Array<IntArray>, edges2: Array<IntArray>, k: Int): IntArray {
        // You always want to connect at the node in the first tree that you're trying to maximize for,
        // so the newly added nodes are as close as possible
        // for the second tree, calculate the number of nodes within k-1 distance from each node, and connect to the max
        // Can do this with BFS of depth k-1 from each node. There may be a more efficient method

        val graph1 = mutableMapOf<Int, MutableSet<Int>>()
        val graph2 = mutableMapOf<Int, MutableSet<Int>>()

        for (edge in edges1) {
            graph1.getOrPut(edge[0]) { mutableSetOf<Int>() }.add(edge[1])
            graph1.getOrPut(edge[1]) { mutableSetOf<Int>() }.add(edge[0])
        }

        for (edge in edges2) {
            graph2.getOrPut(edge[0]) { mutableSetOf<Int>() }.add(edge[1])
            graph2.getOrPut(edge[1]) { mutableSetOf<Int>() }.add(edge[0])
        }
        
        var max = 0
        for (node in graph2.keys) {
            max = maxOf(max, bfs(graph2, node, k - 1))
        }

        return IntArray(graph1.size) { i -> max + bfs(graph1, i, k) }
    }

    fun bfs(graph: Map<Int, Set<Int>>, start: Int, depth: Int): Int {
        if (depth < 0) return 0

        var queue = ArrayDeque<Int>()
        val visited = mutableSetOf<Int>()
        var count = 0
        var distance = 0

        queue.add(start)
        visited.add(start)
        while (queue.isNotEmpty() && distance <= depth) {
            val level = ArrayDeque<Int>()
            while (queue.isNotEmpty()) {
                val node = queue.removeFirst()
                count++

                for (neighbor in graph.getOrDefault(node, mutableSetOf<Int>())) {
                    if (neighbor !in visited) {
                        level.add(neighbor)
                        visited.add(neighbor)
                    }
                }            
            }
            queue = level
            distance++
        }

        return count
    }
}
```
['Kotlin']