Snowflake interview question

Implement the algorithm in selected language