Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find virus originator
let graphNodes = [(1, 2), (2, 3), (2, 4), (4, 5), (4, 6), (5, 4)]
var nodeToIncomingEdgesCountMapping: [Int: Int] = [:]
for node in graphNodes {
if nodeToIncomingEdgesCountMapping[node.0] == nil {
nodeToIncomingEdgesCountMapping[node.0] = 0
}
if nodeToIncomingEdgesCountMapping[node.1] == nil {
nodeToIncomingEdgesCountMapping[node.1] = 0
}
nodeToIncomingEdgesCountMapping[node.1]! += 1
}
for (node, incomingEdgesCount) in nodeToIncomingEdgesCountMapping {
if incomingEdgesCount == 0 {
print("Node is \(node)")
}
}
@jayesh15111988

This comment has been minimized.

Copy link
Owner Author

@jayesh15111988 jayesh15111988 commented Dec 12, 2020

print statement should read,
print("The node where the virus originated is \(node)")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.