FastPrepSmash The Bricks(NG)
Problems/Smash The Bricks(NG)

Smash The Bricks(NG)

Wayfair logoWayfair● MediumFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

There are n bricks arranged in a row at positions numbered from 1 through n, inclusive. There is an array, newtons[n], that contains an integer indicating the number of newtons required to smash a brick. (A newton is a unit of force.)

There are two hammers, one big and one small. The big hammer can smash any brick with one blow. The small hammer reduces the newtons required by 1 for each blow to a brick. For example, a brick requires 3 newtons of force. It will take 1 blow with the big hammer, or 3 blows with the small hammer to smash it. There is a limit to how many times the big hammer can be used.

Determine 3 values:

  • the minimum number of blows to smash all the bricks
  • the 1-based indices of the bricks smashed by the big hammer sorted ascending
  • the 1-based indices of the bricks smashed by the small hammer sorted ascending

Return the values as a 2-dimensional integer array, [[total hits], [big hammer hits], [small hammer hits]]. If a hammer is not used, its index array should be [-1].

Function

smashTheBricks(bigHits: int, newtons: int[]) → long[][]

Complete the function smashTheBricks in the editor below.

smashTheBricks has the following parameters:

  1. int bigHits: the maximum blows with the big hammer
  2. int newtons[n]: the newtons required to smash each brick

Returns long [][], [p][q]: in the form [[ total hits], [sorted indices for big hammer hits], [sorted indices for small hammer hits]]

Examples

Example 1

bigHits = 0newtons = [2]return = [[2], [-1], [1]]

The big hammer cannot be used. The small hammer takes 2 blows to smash the single brick at index 1. The return array is [[2], [-1], [1]].

Example 2

bigHits = 4newtons = [3, 2, 5, 4, 6, 7, 9]return = [[13], [3, 5, 6, 7], [1, 2, 4]]

In this case, it is best to use the big hammer on bricks at sorted indices [3, 5, 7], using 4 hits to smash them all. The small hammer is used on sorted indices [1, 2, 4], which have newtons of 3, 2, and 4. It takes a total of 3 + 2 + 4 = 9 hits with the small hammer. The total blows required = 4 + 9 = 13. The return array is [[13], [3, 5, 6, 7], [1, 2, 4]].

Example 3

bigHits = 9newtons = [7, 9, 3, 2, 5, 8, 4, 6]return = [[8], [1, 2, 3, 4, 5, 6, 7, 8], [-1]]

There are enough bigHits available to smash all of the bricks with the large hammer. The returned arr is [[8], [1, 2, 3, 4, 5, 6, 7, 8], [-1]]:)

Example 4

bigHits = 0newtons = [10000000, 100000000, 1000000000]return = [[1110000000], [-1], [1, 2, 3]]

Since bigHits =0, the big hammer cannot be used. The toal hits required is the sum of the newtons arr, one hit with a small hammer for each newton. The returned arr is [[1110000000], [-1], [1, 2, 3]] :P

Constraints

  • 1 ≤ n ≤ 2 x 105
  • 0 ≤ bigHits ≤ 2 x 105
  • 1 ≤ newtons[i] ≤ 109
  • Elements in newtons[] are distinct.

More Wayfair interview questions

  • UCB1 Multi-Armed Bandit TraceONSITE INTERVIEW · Seen Sep 2026
  • Container With Most WaterPHONE SCREEN · Seen Sep 2026
  • Assign Distinct Letter Values to Minimize XORPHONE SCREEN · Seen Sep 2026
  • Moving Cost by Volume and CategoryONSITE INTERVIEW · Seen Sep 2026
  • DFS Subsequences of a String (For MLE)OA · Seen Sep 2024
  • Number of Divisible Substrings (For MLE)OA · Seen Sep 2024
  • Validating Magical Binary Strings with RegEx (NG)OA · Seen Apr 2024
  • First Three Badge Times per UserPHONE SCREEN · Seen Apr 2022
  • Time of Maximum Mall OccupancyPHONE SCREEN · Seen Apr 2022
  • Longest Common Contiguous User ActionsPHONE SCREEN · Seen Apr 2022

Similar questions at other companies

  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
  • Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
  • Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
  • Maximize Minimum Deployment DifficultyJP Morgan Chase · OAJP Morgan Chase interview questions
  • Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
  • Maximize Center A Package BenefitAmazon · OA
  • EV Charging Cost OptimizationTata Consultancy Services · OATata Consultancy Services interview questions
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
All Wayfair interview questionsSee Wayfair hiring insights
Saved
class Solution {
    public long[][] smashTheBricks(int bigHits, int[] newtons) {
      // write your code here
    }

}
Checking account…