Other Stats
This repo will contain the solutions using Scala for challenges found on:
- Books
- Hacker Rank
- Codility
- CodeFights
Write a function to reduce a given string to its shortest length by doing a series of operations in which we select a pair of adjacent lowercase letters that match, and then we delete them.
We have a collections of rocks, and we represent its minerals in a string with letters from [a-z] and we need to write a function to find the gemstones in the collection of rocks. A gemstone is a mineral that occurs at least once in each of the rocks.
Example:
for ["abc","abaaa","bcd"] b is a gemstone since it appears in the three rocks
for ["ab","cd","ef"] there's no gemstone
Find the smallest positive integer that is NOT in the given array:
Example:
for [1, 3, 6, 4, 1, 2] the missing integer is [5]
for [4, 1, 5, 6, 2] the missing integer is [3]
Given a non-empty zero-indexed array A of N integers, returns the minimal difference
that can be achieved after we split the array on a pivot P. Such as
|(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])|
We need to find the minimum number of jumps a small frog can make from a starting position X to a ending position Y given a jump distance D
We need to write a function that will allow us to mask any given string. We have only two rules
- The mask will only be applied to numbers or numbers separated with dashes (-)
- The mask will not be applied to string containing characters or strings which length is less than 6
- The mask will preserve the first and the last four numbers
For example:
- 8888-9999-9999-0000 -> 8###-####-####-0000
- 1234567890987654321 -> 1##############4321
- Credit Card -> Credit Card
- 123 -> 123
We need to write a function that given a non-negative number it returns the ordinal representation of that number.
Most ordinal numbers end in "th" except for:
- one ⇒ first (1st)
- two ⇒ second (2nd)
- three ⇒ third (3rd)
We need to write a function that given an expression on infix notation will return the result of the operations.
Infix notation is a notation when the numbers are provided first and the operation next.
For example:
- 3 4 + = 3 + 4 = 7
- 3 2 1 - * = (2 - 1) * 3 = 3
- 9 sqrt = sqrt 9 = 3
- P01 (*) Find the last element of a list.
- P02 (*) Find the last but one element of a list.
- P03 (*) Find the Kth element of a list.
- P04 (*) Find the number of elements of a list.
- P05 (*) Reverse a list.
- P06 (*) Find out whether a list is a palindrome.
- P07 (**) Flatten a nested list structure.
- P08 (**) Eliminate consecutive duplicates of list elements.
- P09 (**) Pack consecutive duplicates of list elements into sublists.
- P10 (*) Run-length encoding of a list.
Given a string, reverse the characters and return.
Example:
for "Test" it should return "tseT"
for "Return" it should return "nruteR"
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz
This is a basic problem where we need to find if a number is present on the given array.
Write a function which returns the number of words in a given string - without using REGEX expressions
given "disco1 hero2" or
" disco1 hero2" or
"disco1 hero2 " or
" disco1 hero2 "
then the word count should be 2, the solution should ignore the spaces.
Write a function which prints the index of the last occurrence of the entire sequence within a given array WITHOUT using inbuilt sliding, lastIndexOf and lastIndexOfSlice functions.
If you want to enable the scala check as part of the compile task you can add the following lines to the build.sbt file
lazy val compileScalastyle = taskKey[Unit]("compileScalastyle")
compileScalastyle := scalastyle.in(Compile).toTask("").value
(compile in Compile) := ((compile in Compile) dependsOn compileScalastyle).value
I don't add the line myself since this plugin get executed before the compile step, this can cause problems because if the code does not compile, you’ll get the scalastyle errors messages, not the scalac ones. Great though scalastyle is, it can’t match the error messages produced by the compiler
sbt scalastyle
sbt clean coverage test coverageReport