2018spotifyfellowship

  • Each solution contains the function requested, a test function, and a main function.
    • to run, you can:
      1. uncomment the test function call in the main method
      2. or two compile and run the test file which calls the test function for each question
        • javac test.java
        • java test

Question 1

-- sortByStrings(s,t): Sort the letters in the string s by the order they occur in the string t. You can assume t will not have repetitive characters. For s = "weather" and t = "therapyw", the output should be sortByString(s, t) = "theeraw". For s = "good" and t = "odg", the output should be sortByString(s, t) = "oodg".

MySolution

-- q1.java

Question 2

-- decodeString(s): Given an encoded string, return its corresponding decoded string.

The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is repeated exactly k times. Note: k is guaranteed to be a positive integer.

For s = "4[ab]", the output should be decodeString(s) = "abababab" For s = "2[b3[a]]", the output should be decodeString(s) = "baaabaaa"

MySolution

-- q2.java

Question 3

-- changePossibilities(amount,amount): Your quirky boss collects rare, old coins. They found out you're a programmer and asked you to solve something they've been wondering for a long time.

Write a function that, given an amount of money and an array of coin denominations, computes the number of ways to make the amount of money with coins of the available denominations.

Example: for amount=4 (4¢) and denominations=[1,2,3] (1¢, 2¢ and 3¢), your program would output 4—the number of ways to make 4¢ with those denominations:

1¢, 1¢, 1¢, 1¢ 1¢, 1¢, 2¢ 1¢, 3¢ 2¢, 2¢

My Solution

-- q3.java