Game of Dominoes Problem Statement

Rafiq loves to play with piles of dominoes, especially when they are of equal heights. His father gifted him 'N' piles of dominoes, each with a positive number of stacked dominoes. His father wants to know the minimum cost of making all dominoes in each consecutive window of length 'K' equal in height. The cost for either adding or removing one domino from any pile is one unit.

Example:

Input:
T = 1
N = 5, K = 3
heights = [1, 3, 2, 4, 5]
Output:
Output Example: 1 2 3
Explanation:

The output consists of minimum costs calculated for each window of size 'K'. Each value represents the minimal cost to make the piles in that window equal in height.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 10000
  • 1 <= K <= N
  • 1 <= height[i] <= 105
AnswerBot
2d

Calculate minimum cost to make consecutive windows of domino piles equal in height.

  • Iterate through each window of size 'K' and calculate the minimum cost to make all piles in that window equal in heig...read more

Help your peers!
Add answer anonymously...
Ola Cabs Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter