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
4mo

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 piles equal in height.

  • Keep track of the ...read more

Help your peers!
Select
Add answer anonymously...

Procol Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Power of a Number Problem You are given two integers, X and N. Your task is to c...read more
A Software Developer Intern was asked Q. Minimum Operations to Equalize Array Given an integer array ARR of length N wher...read more
A Software Developer Intern was asked Q. Search in Infinite Sorted 0-1 Array Problem Statement You are provided with an i...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Power of a Number Problem You are given two integers, X and N. Your task is to c...read more
A Software Developer Intern was asked Q2. Minimum Operations to Equalize Array Given an integer array ARR of length N wher...read more
A Software Developer Intern was asked Q3. Pair Sum Problem Statement You are given an integer array 'ARR' of size 'N' and ...read more
Procol Software Developer Intern 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