Running Through Walls with Limited Energy
Updated
Problem statement
You start at integer coordinate 0 on a number line with energy energy. A unit move crosses the gap between two adjacent integers.
A wall position x represents a wall at x+0.5. Crossing that gap in either direction costs its positive thickness; every gap without a wall costs 1. Every crossing costs energy, including repeated crossings of the same wall.
Return the maximum number of distinct walls that can be crossed while spending at most energy.
Function
maximumDistinctWalls(energy: long, wallPositions: int[], thicknesses: int[]) → intExamples
Example 1
energy = 4wallPositions = [-1,0]thicknesses = [2,2]return = 1Either adjacent wall costs 2. Crossing both requires visiting both sides and costs 6.
Example 2
energy = 6wallPositions = [-1,0]thicknesses = [2,2]return = 2Cross one wall, return through it, then cross the other: 2+2+2.
Example 3
energy = 5wallPositions = [0,2]thicknesses = [3,1]return = 2Moving right crosses the first wall for 3, one ordinary gap for 1, and the second wall for 1.
Constraints
0 <= wallPositions.length == thicknesses.length <= 200000.- Wall positions are unique integers in
[-1000000000,1000000000]. 1 <= thicknesses[i] <= 1000000000.0 <= energy <= 10^18.
More Scale AI Online Assessment questions
- Part 2: Batch Access ReviewOA · Seen Nov 2026
- Part 1: The Narrowest KeyOA · Seen Nov 2026
- Build Sessions from Unordered Events (Part 1)OA · Seen Oct 2026
- Match Billing Charges to User Sessions (Part 2)OA · Seen Oct 2026
- Four-Player Trick-Taking Card Game SimulationOA · PHONE SCREEN · Seen Aug 2026
- Free Windows Between Busy IntervalsOA · PHONE SCREEN · Seen Apr 2026
- Compare Labeling Worker AnnotationsOA · Seen Mar 2025
- Count Stable Server SubsegmentsOA · Seen Nov 2024
- Distinct OR Values of Increasing SubsequencesOA · Seen Nov 2024
- Relative Score Graph ComponentsOA · Seen Sep 2023
Similar questions at other companies
- Minimize Warehouse Transfer CostAmazon · OA
- Make the Array PositiveAtlassian · OAAtlassian interview questions
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Optimal TransferSnowflake · OASnowflake interview questions
- Minimum AmountBelvedere Trading · OA
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Minimum Last-Element RelocationsChubb · OAChubb interview questions
- Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions