JOBSEEKER?

Scala Interview Questions

Practice for Scala interviews by solving TestDome questions. Our interview questions are used by more than 7,000 companies and 450,000 individual test takers.

Jobseekers: Certify Your Knowledge

Take a Certification Test

Companies: Use Our Tests for Screening

Buy a Pack Of Candidates

Need to practice your Scala programming skills for an upcoming job interview? Try solving these Scala interview questions that test knowledge of Scala programming concepts such as functions, closures, immutability, and other skills. We’ll provide feedback on your answers, and you can use a hint if you get stuck.

These Scala interview questions are examples of real tasks used by employers to screen job candidates such as Scala developers, back-end developers, full-stack developers, and others that require knowledge of the Scala programming language and its class library.

1. Merge Names

Vector
   
Easy 

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.

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

Bug fixing Immutability Immutable vector
   
Easy  

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.

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

Inheritance OOP
   
Easy 

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())
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

Closures Higher order function
   
Hard  

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.

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:
Scala

Scala Online Test (Easy / Hard)

Scala and SQL Online Test (Easy / Hard)

HTML/CSS

HTML/CSS, JavaScript, Scala, and SQL Online Test (Easy / Hard)

Not exactly what you are looking for? Go to our For Jobseekers section.
Dashboard Start Trial Sign In Home Tour Tests Questions Pricing For Jobseekers