Skip to main content

7 posts tagged with "scala"

View All Tags

· 3 min read

description

this problem is a classic. i got this one from an interview.

you’re given the string as input consisting solely of (, ), and any alpha lower case chars a-z. determine whether the parentheses are balanced.

· 3 min read

description

recentry i have been in interviews to find a new professional opportunity. i got this code challenge from on of those interviews.

what i liked about this particular interview was that the code challenge had progressions/iterations: every time i solved it, the interviewer added constraints or scenarios to support.

the code challenge was to implemente the following function:

/**
* @param header a comma-separated list of languages preferred by the client (in order) `en-US,fr-CA,de-DE`
* @param availableLanguages set of available languages in the platform
* @return the available languages preferred by the client (in order) in the platform
*/
def languages(header: String, availableLanguages: Set[String]): Set[String] = ???

· 4 min read

description

Given an array of positive integers representing the values of coins in your possession, write a function that returns the minimum amount of change (the minimum sum of money) that you cannot create.

The given coins can have any positive integer value and aren't necessarily unique (i.e., you can havemultiple coins of the same value).

For example, if you're given coins = [1, 2, 5], the minimum amount of change that you can't create is 4. If you're given no coins, the minimum amount of change that you can't create is 1.

sample input: coins = [5, 7, 1, 1, 2, 3, 22] sample output: 20

· 4 min read

description

roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

Symbol       Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000

for example, 2 is written as II in roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. the number 27 is written as XXVII, which is XX + V + II.

roman numerals are usually written largest to smallest from left to right. however, the numeral for four is not IIII. instead, the number four is written as IV. because the one is before the five we subtract it making four. the same principle applies to the number nine, which is written as IX. there are six instances where subtraction is used:

  • I can be placed before V (5) and X (10) to make 4 and 9.
  • X can be placed before L (50) and C (100) to make 40 and 90.
  • C can be placed before D (500) and M (1000) to make 400 and 900.

given a roman numeral, convert it to an integer.

· 4 min read

description

Given an integer x, return true if x is palindrome integer. An integer is a palindrome when it reads the same backward as forward. For example, 121 is a palindrome while 123 is not.

constraints

  • x >= 0
  • usage of strings is prohibited