Ad
Code
Diff
  • List<int> twinSumSolutions(List<int> array) {
      
    }
    • // Code goes here
    • List<int> twinSumSolutions(List<int> array) {
    • }
Code
Diff
  • function twinSumSolutions(array) {
      
    }
    • // Code goes here
    • function twinSumSolutions(array) {
    • }
Code
Diff
  • def twin_sum_solutions(array)
    end
    • // Code goes here
    • def twin_sum_solutions(array)
    • end

Your goal is to write a function that takes in an array of numbers. This function then returns another array which contains the sum of every pair in the original array.

twinSumSolutions([2,2,4,4]) // [4, 16]
twinSumSolutions([1,3,3,5]) // [6]
twinSumSolutions([1,2,3,4]) // []

Assume that all of of the elements in the array will always be integers.

// Code goes here

Your goal is to write a function that takes in 2 strings and return the winner in rock paper scissors. For example:

dumbRockPaperScissors("Rock", "Paper") // "Player 2 wins"
dumbRockPaperScissors("Paper", "Rock") // "Player 1 wins"
dumbRockPaperScissors("Scissors", "Scissors") // "Draw"

The twist is that your function needs to be as SLOW as you can make it. The 2 rules:

  • No setTimeouts or anyway to artificially inflate times
  • All code must provide some sort of value toward solving the problem
function dumbRockPaperScissors(player1, player2) {

}

This function has already been writte, but is very slow, operating at O(n^2) complexity. Your goal is to optimize this function to be as fast as possible.

const firstNonRepeatingCharacter = (str) => {
    for (let i = 0; i < str.length; i++) {
        let seenDuplicate = false;
        for (let j = 0; j < str.length; j++) {
            if (str[i] === str[j] && i !== j) {
                seenDuplicate = true;
                break;
            }
        }
        if (!seenDuplicate) {
            return str[i];
        }
    }
    return null; // return null if no unique character is found
};