Codility - StoneWall algo  

by ne on 2021-09-22 under Algo tagged with codility algorithm

A stone wall is to be built using cuboid blocks. We are provided with the height array, we need to find minimum blocks required to build the wall. For detailed description of the algo and example, please refer :

This problem belongs to Codility.


package com.codility;

import java.util.Stack;
 * Created by sthethunderbolt on 15/10/17.
public class SolutionStoneWall {
    public int solution(int[] A){
       Stack stack=new Stack<>();

       for(int i=1;istack.peek()){
           }else if(A[i]stack.peek()){
       return stack.size();
    public static void main(String[] args){
        System.out.println(new SolutionStoneWall().solution(new int[]{1,2,2,2,1}));