Easy solution approach


#1

let the every dwarf count the no. of black hats in front of him. Now (n)th dwarf speaks out the count ,if for (n-1)th the count is same that means he is wearing white cap else black cap.