# Machine Learning Interview Questions

This article mainly focuses on the big picture of traditional machine learning algorithms; as for the details, please check or search on your own.

What is the difference between regression and classification?
There are both types of supervised machine learning. The main difference is that the output variable in the regression is numerical (continuous) while that for classification is categorical (discrete).

What is linear regression? [supervised, regression, mean square error]
We find the relationship between independent and dependent variables by fitting the regression line which is polynomial equation. …

# Deep Learning Interview Questions

In this article, I will focus more on algorithms and theory, including neural network itself, activation function, gradient descent, learning rate, and loss function. And the next piece would discuss programming skills.

What are the steps of deep learning?
1. create a function (neural network)
2. evaluate the goodness of the function
3. pick the best function as the final question answer machine

What is a neural network?
Neural network simulates the ways human learn but is much simpler. It can be imagined as a function. When you feed it input, you are supposed to get an output. …

# LeetCode: Top Interview Problems VIII

238. Product of Array Except Self

Given an array `nums` of n integers where n > 1, return an array `output` such that `output[i]` is equal to the product of all the elements of `nums` except `nums[i]`.

`### Reverse Product List: Time - O(n) / Space - O(n)import numpy as nplength  = len(nums)tableL = np.ones((length+1, ), dtype="int")tableR = np.ones((length+1, ), dtype="int")for k in range(length):    tableL[k+1] = tableL[k] * nums[k]    tableR[length-k-2] = tableR[length-k-1] * nums[length-k-1]return list(tableL * tableR)[:-1]`

240. Search a 2D Matrix II

Write an efficient algorithm that searches for a `target` value in…

# LeetCode: Top Interview Problems VII

200. Number of Islands

Given an `m x n` 2d `grid` map of `'1'`s (land) and `'0'`s (water), return the number of islands.

An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.

`### Breadth First Search: Time - O(n**4) / Space - O(n**2)def mark(pos):    direction = [(1,0), (0,1), (-1,0), (0,-1)]    stack = [pos]    while stack:        pos = stack.pop()        grid[pos][pos] = "0"for k in range(4): tmp_pos = (pos+direction[k], pos+direction[k]) if not 0 <= tmp_pos < len(grid) : continue…`

# LeetCode: Top Interview Problems VI

150. Evaluate Reverse Polish Notation

Evaluate the value of an arithmetic expression in Reverse Polish Notation.

Valid operators are `+`, `-`, `*`, `/`. Each operand may be an integer or another expression.

Note:

• Division between two integers should truncate toward zero.
• The given RPN expression is always valid. That means the expression would always evaluate to a result and there won’t be any divide by zero operation.
`### Stack: Time - O(n) / Space - O(n) stack = [] for token in tokens: try: stack.append(int(token)) except: val1 = stack.pop() val2 = stack.pop() if token == "+": stack.append(int(val2 + val1)) if…`

# LeetCode: Top Interview Problems V

125. Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Note: For the purpose of this problem, we define empty string as valid palindrome.

`### One Pass: Time - O(n) / Space - O(n)palindrome = ""for char in string:    if char.isalnum(): palindrome += char.lower()return palindrome == palindrome[::-1]`

127. Word Ladder

A transformation sequence from word `beginWord` to word `endWord` using a dictionary `wordList` is a sequence of words such that:

• The first word in the sequence is `beginWord`.
• The last word in the sequence is `endWord`.
• Only one…

# LeetCode: Top Interview Problems IV

84. Largest Rectangle in Histogram

Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.

`### Stack: Time - O(n**2) / Space - O(n)heights.append(0)stack = [-1]result = 0for idx in range(len(heights)):    while heights[idx] < heights[stack[-1]]:        h = heights[stack[-1]]  # maximum height        w = idx - 1 - stack[-2] # till the further idx (smaller than "h")        stack.pop()        result = max(result, w*h)    stack.append(idx)return result`

88. Merge Sorted Array

Given two sorted integer arrays `nums1` and `nums2`, merge `nums2` into `nums1`

# LeetCode: Top Interview Problems III

49. Group Anagrams

Given an array of strings `strings`, group the anagrams together. You can return the answer in any order.

An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

`### Sorting: Time - O(nklogk) / Space - O(nk)result = {}for string in strings:    sort = tuple(sorted(string))    if sort not in result:        result[sort] = []    result[sort].append(string)return result.values()`

50. Pow(x, n)

Implement pow(x, n), which calculates x raised to the power n (i.e. xn).

`### Recursion: Time - O(logn) / Space…`

# LeetCode: Top Interview Problems II

21. Merge Two Sorted Lists

Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists.

`### Loop: Time - O(m+n) / Space - O(1)head = ListNode()tail = headwhile l1 or l2:    if   l2 is None or (l1 is not None and l1.val <= l2.val):        tail.next = l1        l1 = l1.next    elif l1 is None or (l2 is not None and l1.val >= l2.val):        tail.next = l2        l2 = l2.next    tail.next.next = None    tail = tail.nextreturn head.next### Recursion if…`

# LeetCode: Top Interview Problems I

1. Two Sum

Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

You can return the answer in any order.

`### Brute Force: Time - O(n**2) / Space - O(n)length = len(nums)for i in range(length):    for j in range(i + 1, length):        if nums[i] + nums[j] == target: return [i, j]### One Pass: Time - O(n) / Space - O(n) complement = {}…` ## Tseng1026

BS in Computer Science, National Taiwan University (NTU); MS in Artificial Intelligence, National University of Singapore (NUS)