FastPrepMaximize Wall Hits
Problems/Maximize Wall Hits

Maximize Wall Hits

OpenAI logoOpenAI● HardNEW GRADOA

Updated Sep 2026

QuestionFunctionExamples

Problem statement

You move along an infinite number line and start at coordinate 0. Each wall is located at a half-integer coordinate of the form x + 0.5, so it lies between two adjacent integer positions.

On each move, you step one unit to the left or right:

  • If the move does not cross a wall, it costs 1 unit of energy.
  • If the move crosses a wall with thickness t, it costs t units of energy and counts as one wall hit.

Walls remain in place after they are hit. You may change direction at any time and may cross the same wall repeatedly; every crossing counts as another hit.

Given the wall positions, their corresponding thicknesses, and the maximum amount of energy you may spend, return the maximum number of wall hits you can make without exceeding the energy limit.

Function

maximizeTheHits(walls: float[], thickness: int[], energy: int) → int

Complete the function maximizeTheHits.

  • float[] walls: wall positions, where walls[i] has thickness thickness[i]
  • int[] thickness: the energy cost of crossing each wall
  • int energy: the maximum total energy available

Return the maximum number of wall hits.

Examples

Example 1

walls = [-1.5, 0.5, 1.5, 5.5]thickness = [2, 4, 8, 3]energy = 3return = 1

Start at x = 0. Move left to x = -1 without crossing a wall, which costs 1 energy. Then move from x = -1 to x = -2, crossing the wall at -1.5. That crossing costs the wall's thickness, 2, and records one hit.

The total cost is 1 + 2 = 3, so no energy remains. Therefore, the maximum number of hits is 1.

More OpenAI interview questions

  • Secret Number Search with One-Call-Delayed FeedbackPHONE SCREEN · Seen Nov 2026
  • Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
  • Grid Infection with Recovery After D DaysPHONE SCREEN · Seen Nov 2026
  • Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
  • Rectangle Point Coverage CountsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Adaptive Calibration ErrorPHONE SCREEN · Seen Nov 2026
  • Elevator Scheduling SimulationPHONE SCREEN · Seen Nov 2026
  • Evaluate Noisy AnnotatorsPHONE SCREEN · Seen Oct 2026
  • Count Routes Through Four Shop TypesOA · Seen Oct 2026

Similar questions at other companies

  • Minimum Satellite Data Transfer IterationsHSBC · OAHSBC interview questions
  • Minimum Cost to Select People for Skill QuotasVisa · OAVisa interview questions
  • Get Maximum EventsAmazon · OA
  • Find Niceness 🌺Goldman Sachs · OAGoldman Sachs interview questions
  • Maximum Meetings from Start Times and DurationsMorgan Stanley · OAMorgan Stanley interview questions
  • Maximum Length Pair ChainInMobi · ONSITE INTERVIEWInMobi interview questions
  • Hard Disk Clustering CostConfluent · OAConfluent interview questions
  • Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
  • Split Array Largest SumAuxoAI · OA
  • Delete and Freeze GameRubrik · OARubrik interview questions

Interview reports that mention this question

  • OpenAI OA: What It Tests (2026)
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public int maximizeTheHits(float[] walls, int[] thickness, int energy) {
      // write your code here
    }

}
Checking account…