Break The Board Problem Statement

Your task is to break a board of given dimensions 'L' by 'W' into 'L' * 'W' smaller squares, ensuring the total cost of breaking is minimized.

Input:

The first line contains an integer 'T' indicating the number of test cases.
For each test case, the input is as follows:
- A line with two space-separated integers, 'L' and 'W', representing the length and width.
- A line with 'L' - 1 integers denoting the cost of each horizontal cut.
- A line with 'W' - 1 integers denoting the cost of each vertical cut.

Output:

For each test case, output an integer representing the minimum cost required to break the board into 'L' * 'W' squares.

Example:

Input:
1
4 3
2 1 3
1 2
Output:
10

Constraints:

  • 1 ≤ T ≤ 10
  • 2 ≤ L, W ≤ 104
  • 1 ≤ costL[i], costW[i] ≤ 105
  • Time Limit: 1 second

Note:

You are not required to print anything manually; implement the function to get the expected results.

AnswerBot
4mo

Minimize cost of breaking a board into smaller squares by optimizing horizontal and vertical cuts.

  • Iterate through all possible horizontal and vertical cuts to find the minimum cost

  • Use dynamic programm...read more

Help your peers!
Select
Add answer anonymously...

Twitter Software Developer interview questions & answers

A Software Developer was asked 6mo agoQ. Explain the process of calling an API.
A Software Developer was asked Q. Break The Board Problem Statement Your task is to break a board of given dimensi...read more
A Software Developer was asked Q. Fibonacci Number Verification Identify if the provided integer 'N' is a Fibonacc...read more

Popular interview questions of Software Developer

A Software Developer was asked Q1. Break The Board Problem Statement Your task is to break a board of given dimensi...read more
A Software Developer was asked Q2. Fibonacci Number Verification Identify if the provided integer 'N' is a Fibonacc...read more
A Software Developer was asked Q3. Design a Facebook-like application.
Twitter Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits