In a village there are n houses , some have electricity some dont. Those having electricity are labeled as 1 and others 0.Houses are arranged in a line from left to right (1 to n).let x1 x2 x3..... be coordinates of the houses.(1= < x1< x2< x3...)The houses having electricity are to be connected with those which don't have.What is the minimum length of wire required so that all houses have electricity??Example:No. of houses n=3Label 100coordinates 1,5,6Minimum length req= 6-1=5 (connect first and third house. The wire will go through 2nd house thus all have electricity)2)label 10100coordinates 1,4,6,9,88Minimum length = 84=[(6-4)+(88-6)]
How do i construct a code for this problem?
logic;pattern recognition