Interview Questions

Find out the Longest Path in a matrix

Find out the Longest Path in a matrix

Given an m-by-n matrix with positive integers, determine the length of the longest path of increasing within the matrix. For example, consider the input matrix:[1 2 34 5 67 8 9] The answer should be 5 since the longest path would be 1-2-5-6-9 def isValid(mat, i, j): return 0 <= i < len(mat) and 0 <= j < len(mat) def findLongestPath(mat, i, j): if not isValid(mat, i, j): return [] path = [] if i > 0 and mat[i - 1][j] - mat[i][j] == 1: path = findLongestPath(mat, i - 1, j) if j + 1 < len(mat) and mat[i][j…
Read More
Explain the central limit theorem and give examples of when you can use it in a real-world problem.

Explain the central limit theorem and give examples of when you can use it in a real-world problem.

The center limit theorem states that if any random variable, regardless of the distribution, is sampled a large enough time, the sample mean will be approximately normally distributed. This allows for studying the properties of any statistical distribution as long as there is a large enough sample size. Important remark from Adrian Olszewski:⚠️ we can rely on the CLT with means (because it applies to any unbiased statistic) only if expressing data in this way makes sense. And it makes sense *ONLY* in the case of unimodal and symmetric data, coming from additive processes. So forget skewed, multi-modal data with mixtures of…
Read More
What are the motivation behind random forests and mention two reasons why they are better than individual decision trees?

What are the motivation behind random forests and mention two reasons why they are better than individual decision trees?

The motivation behind random forest or ensemble models in general in layman's terms, Let's say we have a question/problem to solve we bring 100 people and ask each of them the question/problem and record their solution. Next, we prepare a solution which is a combination/ a mixture of all the solutions provided by these 100 people. We will find that the aggregated solution will be close to the actual solution. This is known as the "Wisdom of the crowd" and this is the motivation behind Random Forests. We take weak learners (ML models) specifically, Decision Trees in the case of…
Read More