Codility - StoneWall algo  

by ne on 2022-02-16 under Algo/DS/Problems 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 : https://app.codility.com/programmers/lessons/7-stacks_and_queues/stone_wall/

This problem belongs to Codility.

Solution:


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<>();

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