Stokastik

Machine Learning, AI and Programming

Tag: Merge Stones

Leetcode : Minimum Cost To Merge Stones

Problem Statement Solution: It might be 'tempting' to think that the problem can be solved using a greedy approach, i.e. merge the K consecutive stones with the minimum cost in each step. But the greedy approach is not optimal, for e.g. if the stones array is [6,4,4,6] and K=2, then the greedy approach would result in a minimum cost of 42 whereas the optimal cost is 40. The greedy approach […]

Continue Reading →