Matrix Land
You are playing a matrix-based game with the following setup and rules: You are given a matrix A with n rows and m columns. Each cell contains some points. When a player passes a cell their score increases by the number written in that cell and the number in the cell becomes 0. (If the cell number is positive their score increases, otherwise it decreases.) The player starts from any cell in the first row and can move left, right or down. The game is over when the player reaches the last row
View Solution →Knapsack
Given an array of integers and a target sum, determine the sum nearest to but not exceeding the target that can be created. To create the sum, use any element of your array zero or more times. For example, if arr = [2,3,4] and your target sum is 10, you might select [2,2,2,2,2], [2,2,3,3] or [3,3,31]. In this case, you can arrive at exactly the target. Function Description Complete the unboundedKnapsack function in the editor below. It must return an integer that represents the sum near
View Solution →Bricks Game
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend will also play optimally and you make the first move. As an example, bricks are numbered arr = [1,2,3,4,5]. You can remove either [1]=1, [1,2]=3 or [1,2,3] = 6. For your friend, yo
View Solution →The Longest Increasing Subsequence
An Introduction to the Longest Increasing Subsequence Problem The task is to find the length of the longest subsequence in a given array of integers such that all elements of the subsequence are sorted in strictly ascending order. This is called the Longest Increasing Subsequence (LIS) problem. For example, the length of the LIS for [15,27,14,38,26,55,46,65,85] is 6 since the longest increasing subsequence is [15,27,38,55,65,85]. Here's a great YouTube video of a lecture from MIT's Open
View Solution →Coin on the Table
You have a rectangular board consisting of n rows, numbered from 1 to n, and m columns, numbered from 1 to m. The top left is (1,1) and the bottom right is (n, m). Initially - at time - there is a coin on the top-left cell of your board. Each cell of your board contains one of these letters: *: Exactly one of your cells has letter '*'. U: If at time t the coin is on cell (i, j) and cell (i, j) has letter 'U', the coin will be on cell (i-1, j) at time t+1, if i>1. Otherwise, there is no co
View Solution →