Celebrity problem

Go lang implementation for Celebrity problem is as listed below. This algorithm does not use recursion and has following complexities:

time complexity: O(n²)
space complexity: O(n)

package main

import (
"fmt"
)

func main() {
const numOfPeople = 4

matrix := [numOfPeople][numOfPeople] int {
[numOfPeople] int{0, 0, 1, 0},
[numOfPeople] int{1, 0, 1, 0},
[numOfPeople] int{0, 0, 0, 0},
[numOfPeople] int{1, 1, 1, 1},
}

indegree := []int{0, 0, 0, 0}
outdegree := []int{0, 0, 0, 0}

for i:=0; i < numOfPeople; i++ {
for j:=0; j < numOfPeople; j++ {
if matrix[i][j] == 1 {
indegree[j]++
outdegree[i]++
}
}
}

for i:=0; i<numOfPeople; i++ {
if (outdegree[i] == 0) && (indegree[i] == numOfPeople - 1) {
fmt.Println("Celebrity found: ", i)
return
}
}

fmt.Println("Celebrity not found")
}

#go-lang #algorithms