Description
Solutions
Maximize The Hits
πŸ‘©β€πŸŽ“ NEW GRAD

We have a number line and there are walls provided at coordinates x+0.5, where x is any integer. Each wall has some thickness to it. The player starts from x = 0 and every time they take a step to the left or right, they are exerting energy of 1 unit. However, when they go through a wall of thickness t, they are exerting energy of t units. You are also given the maximum energy you can spend in the whole simulation. The main goal of this algorithm is to return the maximum number of walls you can hit. (After you hit the wall it still exists so you can keep going back and forth to hit the same wall). You can also go left and right at any point in time.

NOTE: You always start from x - 0 :)

Function Description

Complete the function maximizeTheHits in the editor.

maximizeTheHits has the following parameters:

  1. 1. int[] walls: an array of integers representing the positions of the walls
  2. 2. int[] thickness: an array of integers representing the thickness of each wall
  3. 3. int energy: the maximum energy you can spend

Returns

int: the maximum number of walls you can hit

Example 1:

Input:  walls = [-1.5, 0.5, 1.5, 5.5], thickness = [2, 4, 8, 3], energy = 3
Output: 1
Explanation:

Since you start at x = 0 and in order to maximize the number of walls you go to the left and hit the wall positioned at -1.5. The energy to reach that wall was 1 (x=0 to x=-1) and the energy to hit that wall was its thickness i.e. 2 (x=-1 to x=-2). Now your position is x=-2 but you have depleted your energy. Hence the answer for this example should be 1.

Constraints:
    πŸ…πŸ…
Thumbnail 0
Testcase

Result
Case 1

input:

output: