Try to solve 4 Scala interview questions below. Hints can help you find answers to questions you are having trouble with.
1. Merge Names
Vectors are one-dimensional collections that act as dynamic arrays. In many languages, Vectors offer the flexibility of dynamically sized arrays, the simplicity of access of arrays, and are more performant than more ubiquitous collections in most scenarios.
Not enough data for chart
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.
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
Everyone makes mistakes. A good programmer should be able to find and fix a bug in their or someone else's code.
The ability to discern which objects are mutable and which are immutable allows a programmer to understand the effects of possible changes to an object's state.
A vector is a general-purpose, immutable data structure. Because vectors strike a good balance between fast random selections and fast random functional updates, they are currently the default implementation of immutable indexed sequences.
# of candidates
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.
In object-oriented programming, inheritance is the mechanism of basing a class upon another class, retaining similar implementation. Inheritance allows programmers to reuse code and is a must know topic for every programmer who works with OOP languages.
Object-oriented programming is a paradigm based on encapsulating logic and data into objects, which may then contain fields and procedures. Many of the most widely used programming languages are based on OOP, making it a very important concept in modern programming.
Not enough data for chart
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()