Graphnile interview question

Basics of Data Analysis, submit the algorithm