I interviewed with Snowflake for Software Engineer role in Data Application Foundations team. Since there arent many problems posted for Snowflake interview I would like to share my experience.
Problem description
""" there a total of n courses a student can take. labeled from 0 to n-1. You have an array of pre-requisities where p[i]= [a,b] indicates that student must take course b first , if student wants to take course a.
For ex. pair [0,1] indicates that to take Course 0, you have to take course1.
Return ordering of courses student should take to finish all courses. If there are multiple valid answers, return any of them. If its is impossible to finish all courses return an empty array
Example
n=5, [0,1,2,3,4]
p= [ {0,1}, {2,3}, {0,2}]
expected output= [1,3,2,0,4] or [3,2,1,0,4]
"""
I proposed modelling this a graph data structure, directed graph in particular.
I also used a visited boolean array of each node in this graph, to model traversal/processing of each neighbor of current node.
This will help in achieving ordering of nodes aka courses in result list.
I couldnt solve complete problem and write pseudo code either.
Would really appreciate pointers from community here to provide pointers on this problem/pattern