Skip to content
Hoodie for your thoughts: take the Developer Skills Survey for a chance to win free merch Start survey
69% of tech leaders are preparing their teams for GenAI. Uncover more insights in the AI Skills Report. Read now
Adapt your hiring strategy for an AI-powered future. Uncover more insights in our latest whitepaper. Read now
Artificial Intelligence

11 Artificial Intelligence Interview Questions You Should Know

Written By Ryan Loftus | September 15, 2022

Since its inception, artificial intelligence (AI) has become an innovative discipline driving the creation of the world’s most promising technologies. So promising, in fact, that Google CEO Sundar Pichai compared the advancement of artificial intelligence to the discovery of fire and electricity. With potential applications including cancer treatment, space exploration, and self-driving cars, the need for organizations to assess, hire for, and cultivate AI skills is vast.

Artificial intelligence interview questions have been a critical component of technical hiring for decades. If you’re a developer, engineer, or data scientist with a specialization in artificial intelligence, the ability to demonstrate your AI and machine learning skills in an interview is critical to getting hired.

To succeed in an AI interview, you’ll need to hone your coding, statistics, machine learning, and AI by preparing for the styles of problems you might encounter. In this post, we review the AI questions you need to know to land your next job.

What to Expect in an AI Interview

During an AI interview, candidates are challenged to solve coding problems that cover a wide range of topics, including:

  • Alpha-beta pruning
  • Bot building
  • Combinatorial search
  • Image analysis and processing
  • Natural language processing
  • Probability and statistics
  • Machine learning

AI interview questions can appear in the hiring process for a variety of roles, including software engineers and data scientists.

Basic AI Interview Challenges

Let’s cover five examples of basic AI problems. These challenges are simple in nature, testing a single concept. They can be solved in a collaborative integrated development environment (IDE). Access the sample inputs, sample outputs, and base code by clicking the Solve Problem at the end of every prompt.

  • Bot Saves Princess (Bot Building)
  • BotClean (Bot Building)
  • BotClean Stochastic (Bot Building)
  • Image Segmentation #1 (Image Analysis)
  • Compute the Cross-Entropy (Natural Language Processing)

Bot Saves Princess (Bot Building)

A princess is trapped in one of the four corners of a square grid. You are in the center of the grid and can move one step at a time in any of the four directions. Can you rescue the princess?

Input format

The first line contains an odd integer N (3 <= N < 100) denoting the size of the grid. This is followed by an NxN grid. Each cell is denoted by ‘-‘ (ascii value: 45). The bot position is denoted by ‘m’ and the princess position is denoted by ‘p’. The grid is indexed using matrix convention.

Output Format

Print out the moves you will take to rescue the princess in one go. The moves must be separated by ‘\n’, a new line. The valid moves are LEFT or RIGHT or UP or DOWN.

Sample Input

3

-m-

p–

Sample Output

DOWN

LEFT

Task

Complete the function displayPathtoPrincess which takes in two parameters – the integer N and the character array grid. The grid will be formatted exactly as you see it in the input, so for the sample input the princess is at grid[2][0]. The function should output moves (LEFT, RIGHT, UP or DOWN) on consecutive lines to rescue/reach the princess. The goal is to reach the princess in as few moves as possible.

The above sample input is just to help you understand the format. The princess (‘p’) can be in any one of the four corners.

Scoring

Your score is calculated as (NxN – number of moves made)/10, where N is the size of the grid.

Solve Problem

BotClean (Bot Building)

The goal of Artificial Intelligence is to create a rational agent that receives input from the environment through sensors and acts on the environment with actuators. In this challenge, you will program a simple bot to perform the correct actions based on environmental input.

MarkZoid is a cleaning bot whose sensor is a head mounted camera and whose actuators are the wheels beneath it. It’s used to clean the floor. The bot here is positioned at the top left corner of a 5×5 grid. Your task is to move the bot to clean all the dirty cells.

Input Format

The first line contains two space separated integers which indicate the current position of the bot. The board is indexed using matrix convention

5 lines follow representing the grid. Each cell in the grid is represented by any of the following three characters:

  • ‘b’ (ascii value 98) indicates the bot’s current position
  • ‘d’ (ascii value 100) indicates a dirty cell 
  • ‘-‘ (ascii value 45) indicates a clean cell

Note: If the bot is on a dirty cell, the cell will still have ‘d’ on it.

Output Format

The output is the action that is taken by the bot in the current step, and it can be either one of the movements in 4 directions or cleaning up the cell in which it is currently located. The valid output strings are LEFT, RIGHT, UP, DOWN, or CLEAN. If the bot ever reaches a dirty cell, output CLEAN to clean the dirty cell. Repeat this process until all the cells on the grid are cleaned.

Task

Complete the function next_move and print the bot’s next move. The function takes in three parameters: 

  • posr and posc: the coordinates of the bot’s current position 
  • board: indicates the board state

The codechecker will keep calling the function next_move until the game is over or you make an invalid move.

Solve Problem

BotClean Stochastic (Bot Building)

A deterministic environment is one where the next state is completely determined by the current state of the environment and the task executed by the agent. If there is any randomness involved in determining the next state, the environment is stochastic.

The previous problem, Bot Clean, took place in a deterministic environment. In this version, the bot is given 200 moves to clean as many dirty cells as possible. The grid initially has 1 dirty cell. When the bot cleans this cell, a new cell in the grid is made dirty. The new cell can be anywhere in the grid.

The bot here is positioned at the top left corner of a 5×5 grid. Your task is to move the bot to the dirty cell and clean it.

Input Format

The first line contains two single spaced integers which indicates the current position of the bot. The grid is indexed (x, y) 0<=x,y<=4 top to bottom and left to right respectively. 

5 lines follow showing the grid rows. Each cell in the grid is represented by any of the following 3 characters:

  • ‘b’ (ascii value 98) – the bot’s current position (if on a clean cell).
  • ‘d’ (ascii value 100) – a dirty cell (even if the robot is present on top of it).
  • ‘-‘ (ascii value 45) – a clean cell in the grid.

Output Format

Output is the action that is taken by the bot in the current step and it can be any of the movements in 4 directions or cleaning the cell in which it is currently located. The output formats are LEFT, RIGHT, UP, DOWN, or CLEAN. Output CLEAN to clean the dirty cell. Repeat this process until all the cells on the grid are cleaned.

Task

Complete the function next_move and print the bot’s next move. The function takes in three parameters: 

  • posr and posc: the coordinates of the bot’s current position 
  • board: indicates the board state

Solve Problem

Image Segmentation #1 (Image Analysis)

Consider the following binary image where 0 is the background and 1 represents a pixel on an object:

000110001010

111011110001

111010010010

100000000100 

If we segment this image on a model based on simple 4 pixel connectivity, how many 4-connected objects do you obtain? Enter the appropriate integer in the text box below.

Alternatively, you may submit a program which computes and displays the required integer.

Solve Problem

Compute the Cross-Entropy (Natural Language Processing)

The perplexity of a bigram model is 170. Compute its cross-entropy corrected to 2 decimal places.

You can either submit the final answer in the plain-text mode or submit a program in the language of your choice to compute the required value.

Your answer should look like this: 5.50  

Do not use any extra leading or trailing spaces or newlines.

Solve Problem

Advanced AI Interview Challenges 

The following are five examples of advanced AI problems. These challenges add more complexity to the concepts from the previous section and test more advanced AI concepts, including statistics and machine learning, and natural language processing. These challenges are meant to be solved in a collaborative integrated development environment (IDE). Access the sample inputs, sample outputs, and base code by clicking Solve Problem at the end of every prompt.

  • Similarity Scores (Natural Language Processing)
  • Missing Stock Prices (Statistics and Machine Learning)
  • Poisson Distribution #3 (Probability and Statistics)
  • Battleship (Bot Building)
  • To Be or What to Be, That Is the Question (Natural Language Processing)

Similarity Scores (Natural Language Processing)

You are provided with four documents, numbered 1 to 4, each with a single sentence of text. Determine the identifier of the document D which is the most similar to the first document, as computed according to the TF-IDF scores.

  1. I’d like an apple.
  2. An apple a day keeps the doctor away.
  3. Never compare an apple to an orange.
  4. I prefer scikit-learn to orange.

Output the integer D (which may be either 2 or 3 or 4), leaving no leading or trailing spaces.

You may either compute the answer manually and submit it in plain-text mode, or submit a program which computes the answer, in a language of your choice.

Solve Problem

Missing Stock Prices (Statistics and Machine Learning)

A time series of a stock’s highest price during a trading day is provided to you. In each test case, the highest prices are missing for certain days. By analyzing the data, identify the missing prices for those particular days.

Input Format

The first line contains an integer N, which is the number of rows of data to follow. This is followed by N rows of data, each of which contains a time-stamp in the first column and the day’s highest price for the stock in the second column. There is a tab delimiter between the two columns of data.

There are exactly twenty rows in each input file, where the day’s highest price is missing. The missing prices are marked as “Missing_1”, “Missing_2″ …”Missing_20”. These missing records have been randomly dispersed in the rows of data.

Output Format

The output should contain exactly twenty rows, each containing your predicted value, for each of the missing values (Missing_1, Missing_2 … Missing_20) in that order.

Solve Problem

Poisson Distribution #3 (Probability and Statistics)

The number of calls coming per minute into a hotel’s reservation center is Poisson random variable with mean 3. 

  1. Find the probability that no calls come in a given 1 minute period. Assume that the number of calls arriving in two different minutes are independent. 
  2. Find the probability that at least two calls will arrive in a given two minute period.

Submission Modes and Output Format

Your output should be two floating point/decimal numbers (as answers to prompts 1 and 2, respectively). The output should be correct to three places of decimal. Alternatively, you may submit an R program, which uses the above parameters (hard-coded) and computes the answer.

Sample Output Format

9.123

8.345

Solve Problem

Battleship (Bot Building)

Battleship is a popular 2-player game that takes place on a 10 x 10 board. Ships of various sizes are placed on the 10 x 10 board either horizontally or vertically. The positions of the ships are hidden to the user. Your task is to sink all the ships.

Ships of the following size are given to each player.

  • Submarine (1 x 1) – 2 nos
  • Destroyer (2 x 1) – 2 nos
  • Cruiser (3 x 1) – 1 nos
  • Battleship(4 x 1) – 1 nos
  • Carrier (5 x 1) – 1 nos

In this version of the game, you will initially specify the positions of your ships in a specific format and then start attacking the positions of your opponent. You can place the ships side by side.

Input Format

The first move would be a 4 letter word “INIT” which indicates that you are to place your ships. The next set of moves follow the format as mentioned below.

The first line contains N, indicating the size of the board. N lines follow each line containing 10 characters. 

  • If a cell is hit, it is denoted by character h (ascii value 104)
  • If a cell is a miss it is denoted by character m (ascii value 109)
  • If all the positions of a ship is destroyed, each of its positions on the board is denoted by character d (ascii value 100)
  • If a cell is not attacked by the player, it is denoted by the character “-” (ascii value 45).

The board is indexed according to Matrix Convention

Constraint: N = 10

Output Format

For the first move, print the ships in the following format. In ascending order of the size of each ship, print the start and end position of the ship. For submarines, print the start position. The following lists a sample output for ship positions: 

0 0

4 2

6 4:7 4

3 7:3 8

7 7:7 9

1 4:4 4

4 0:8 0

For the next set of moves, output the cell to be hit in your current move. The output consists of two integers R and C separated by a single space.

Solve Problem

To Be or What to Be, That Is the Question (Natural Language Processing)

The verb “to be”, in its different forms, is one of the most commonly used building blocks of the English language. There are many examples and different forms of “to be“.

You are provided a paragraph of text in which some of the derivatives of this verb have been blanked out. At various points in the text, occurrences of ‘am’ ,’are’, ‘were’, ‘was’, ‘is’, ‘been’, ‘being’, and ‘be’ have been blanked out and replaced with a series of four consecutive hyphens (—-). Your task is to identify which of these words can appropriately fill up these blanks.

Input Format

The input will contain two lines. The first line will contain only one integer N, which will equal the number of blanks in the text. The second line contains one paragraph of text. Several occurrences of the words mentioned previously have been blanked out and replaced by four consecutive hyphens (—-). These are the blanks which you need to fill up with one of the following words: ‘am’,’are’,’were’,’was’,’is’,’been’,’being’,’be’.

Output Format

The output should contain exactly N lines. This is followed by the appropriate words which need to be filled up in the N blanks in the provided paragraph of text, in the same order as the blanks which they are intended for, respectively.

Solve Problem

Challenge Problem: Click-o-Mania (Bot Building)

Here is an advanced-level artificial intelligence problem that covers bot building. Access the sample illustration, sample inputs, sample outputs, and base code by clicking Solve Problem at the end of the prompt. Only 2.38% of developers in the HackerRank Community that have attempted this problem have succeeded. Good luck!

Clickomania is a one player game consisting of a rectangular grid of square blocks, each colored in one of k colors. Adjacent blocks horizontally and vertically of the same color are considered to be a part of the same group. A move selects a group containing at least two blocks and removes those blocks, followed by two “falling” rules:

  1. Any blocks remaining above the holes created fall down through the same column.
  2. Any empty columns are removed by sliding the succeeding columns left.

In this game, you have to code a bot such that it eliminates as many possible blocks from the grid. The top left of the grid is indexed (0,0) and the bottom right of the grid is indexed (rows-1,columns-1).

Input Format

The first line of the input is three space separated integers, x y k, where:

  • x is the width of the grid
  • Y is the height of the grid
  • k is the number of colors in the grid
  • grid – a 2D array of characters which is the board.

An empty cell in the grid will be denoted by ‘-‘.

Output Format

Output two space-separated integers that represent the coordinates of the block you choose to remove from the grid. You can output any one of the nodes of the group which you choose to remove.

Constraints

  • 1 <= k <= 7
  • Each color can be any of ‘V’,’I’,’B’,’G’,’Y’,’O’,’R’ (VIBGYOR)

Challenge

Complete the function nextMove which takes integers x, y, k, and grid.

Scoring

Your score depends on the number of blocks left (count), the size of the board and the number of colors (k).

Score = (1 – count/20) x 5 x k

If count >= 20, a nominal score of 0.01 would be given.

The maximum scores for the test cases of this challenge are 10, 15, 25, and 30, for a total score of 80.

Solve Problem

Resource for Improving AI Knowledge

HackerRank Artificial Intelligence Questions

HackerRank Interview