Scala Interview Questions

Want to become an expert in cracking Scala interview questions?

Start with practicing the questions below. Whether a question involves multiple choice or live coding, we will give you hints as you go and tell you if your answers are correct or incorrect.

After that, take our timed public Scala Interview Questions Test.

To use our service for testing candidates, buy a pack of candidates.


1. Merge Names

Scala Vector Public New

Implement the uniqueNames function. When passed two vectors of names, it will return a vector containing the names that appear in either or both input vectors. The returned vector should have no duplicates.

For example, calling MergeNames.uniqueNames(Vector("Ava", "Emma", "Olivia"), Vector("Olivia", "Sophia", "Emma")) should return a vector containing Ava, Emma, Olivia, and Sophia in any order.

Easy 
10min
Scala  
 


  •   Example case: java.lang.UnsupportedOperationException at MergeNames$.uniqueNames(MergeNames.scala:3)
  •   Each vector has distinct names: java.lang.UnsupportedOperationException at MergeNames$.uniqueNames(MergeNames.scala:3)
  •   Each vector has duplicate names: java.lang.UnsupportedOperationException at MergeNames$.uniqueNames(MergeNames.scala:3)
  •   Vectors have some names in common: java.lang.UnsupportedOperationException at MergeNames$.uniqueNames(MergeNames.scala:3)


2. Player Inventory

Scala Bug fixing Immutability Public New

The code for the PlayerInventory class is not working. When a user starts a new account, PlayerInventory is initialized with basic items. It should also be possible to add and drop items from the inventory, with duplicate items added and removed separately.

For example, if "lumber" was added to the inventory and "stone" was removed, getItems() should return a Vector containing "lumber", "magic potion", and "lumber", in any order.

Fix the bugs.

Easy 
10min
Scala  
 


  •   Example case: Wrong answer
  •   Duplicates added separately: Wrong answer
  •   Duplicates removed separately: Wrong answer
  •   Unique items are added and removed: Wrong answer


3. User Input

Scala OOP Public New

User interface contains two types of user input controls: TextInput, which accepts all characters and NumericInput, which accepts only digits.

Implement the class TextInput that contains:

  • Public method def add(c : Char) - concatenates the given character to the current value
  • Public method def getValue: String - returns the current value

Implement the class NumericInput that:

  • Inherits from TextInput
  • Overrides the add method so that each non-numeric character is ignored

For example, the following code should output "10":

val input: TextInput = new NumericInput()
input.add('1')
input.add('a')
input.add('0')
println(input.getValue())
Easy 
15min
Scala  
 


  •   Example Case: java.lang.ClassCastException
  •   Adding various characters to TextInput: java.lang.NoSuchMethodException
  •   Adding numeric characters to NumericInput: java.lang.ClassCastException
  •   Adding various characters to NumericInput: java.lang.ClassCastException


4. Pipeline

Scala Closures Public New

As part of a data processing pipeline, complete the implementation of the makePipeline function:

  • The function should accept a variable number of functions, and it should return a new function that accepts one parameter arg.
  • The returned function should call the first function in the makePipeline with the parameter arg, and call the second function with the result of the first function.
  • The returned function should continue calling each function in the makePipeline in order, following the same pattern, and return the value from the last function.

For example, makePipeline((x: Int) => x * 3, (x: Int) => x + 1, (x: Int) => x / 2), and then calling the returned function with 3 should return 5.

Hard 
10min
Scala  
 


  •   Example case: Wrong answer
  •   Various functions: Wrong answer
  •   Various data types: Wrong answer


If you feel ready, take one of our timed public Scala Interview Questions tests:
  • HTML/CSS, JavaScript, Scala, and SQL Online Test (Easy / Hard)
  • Scala Online Test (Easy / Hard)
  • Scala and SQL Online Test (Easy / Hard)
Not exactly what you are looking for? Go to our For Jobseekers section.