Consider N coins aligned in a row.

Consider N coins aligned in a row. Each coin is showing either heads or tails. The adjacency of these coins is the number of adjacent pairs of coins with the same side facing up.

It must return the maximum possible adjacency that can be obtained by reversing exactly one coin (that is, one of the coins must be reversed). Consecutive elements of array A represent consecutive coins in the row. Array A contains only 0s and/or 1s: 0 represents a coin with heads facing up; 1 represents a coin with tails facing up. For example, given array A consisting of six numbers, such that:

A[0] = 1
A[1] = 1
A[2] = 0
A[3] = 1
A[4] = 0
A[5] = 0

the function should return 4. The initial adjacency is 2, as there are two pairs of adjacent coins with the same side facing up, namely (0, 1) and (4, 5). After reversing the coin represented by A[2], the adjacency equals 4, as there are four pairs of adjacent coins with the same side facing up, namely: (0, 1), (1, 2), (2, 3) and (4, 5), and it is not possible to obtain a higher adjacency. The same adjacency can be obtained by reversing the coin represented by A[3].

I should mention here that number of elements can be from 1....10'000. And it has to be done as O(N)

 

http://v.17173.com/playlist_30551122.html
http://v.17173.com/playlist_30551152.html
http://v.17173.com/playlist_30551177.html
http://v.17173.com/playlist_30551927.html
http://v.17173.com/playlist_30551978.html
http://v.17173.com/playlist_30552010.html
http://v.17173.com/playlist_30552245.html
http://v.17173.com/playlist_30552338.html
http://v.17173.com/playlist_30552426.html
http://v.17173.com/playlist_30552727.html
http://v.17173.com/playlist_30552929.html
http://v.17173.com/playlist_30553249.html
http://v.17173.com/playlist_30553401.html
http://v.17173.com/playlist_30553544.html
http://v.17173.com/playlist_30553846.html
http://v.17173.com/playlist_30553989.html
http://v.17173.com/playlist_30553961.html
http://v.17173.com/playlist_30554410.html
http://v.17173.com/playlist_30555471.html
http://v.17173.com/playlist_30555571.html
http://v.17173.com/playlist_30555755.html
http://v.17173.com/playlist_30555806.html
http://v.17173.com/playlist_30555822.html
http://v.17173.com/playlist_30555993.html
http://v.17173.com/playlist_30556054.html
http://v.17173.com/playlist_30556085.html
http://v.17173.com/playlist_30556116.html
http://v.17173.com/playlist_30556099.html
http://v.17173.com/playlist_30556123.html
http://v.17173.com/playlist_30556218.html
http://v.17173.com/playlist_30556311.html
http://v.17173.com/playlist_30556341.html
http://v.17173.com/playlist_30556369.html
http://v.17173.com/playlist_30556409.html
http://v.17173.com/playlist_30556438.html
http://v.17173.com/playlist_30556425.html
http://v.17173.com/playlist_30556543.html
http://v.17173.com/playlist_30556578.html
http://v.17173.com/playlist_30556637.html
http://v.17173.com/playlist_30556724.html
http://v.17173.com/playlist_30556712.html
http://v.17173.com/playlist_30556748.html
http://v.17173.com/playlist_30556736.html
http://v.17173.com/playlist_30556743.html
http://v.17173.com/playlist_30556846.html
http://v.17173.com/playlist_30556892.html
http://v.17173.com/playlist_30556944.html
http://v.17173.com/playlist_30556989.html
http://v.17173.com/playlist_30556980.html
http://v.17173.com/playlist_30557007.html
http://v.17173.com/playlist_30557026.html
http://v.17173.com/playlist_30557048.html
http://v.17173.com/playlist_30557098.html
http://v.17173.com/playlist_30557195.html
http://v.17173.com/playlist_30557228.html
http://v.17173.com/playlist_30557254.html
http://v.17173.com/playlist_30557238.html
http://v.17173.com/playlist_30557277.html
http://v.17173.com/playlist_30557304.html
http://v.17173.com/playlist_30557344.html
http://v.17173.com/playlist_30557352.html
http://v.17173.com/playlist_30557400.html
http://v.17173.com/playlist_30557530.html
http://v.17173.com/playlist_30557517.html
http://v.17173.com/playlist_30557523.html
http://v.17173.com/playlist_30557533.html
http://v.17173.com/playlist_30557602.html
http://v.17173.com/playlist_30557675.html
http://v.17173.com/playlist_30557622.html
http://v.17173.com/playlist_30557665.html
http://v.17173.com/playlist_30557710.html
http://v.17173.com/playlist_30557856.html
http://v.17173.com/playlist_30557824.html
http://v.17173.com/playlist_30557826.html
http://v.17173.com/playlist_30557842.html
http://v.17173.com/playlist_30557924.html
http://v.17173.com/playlist_30557949.html
http://v.17173.com/playlist_30557967.html
http://v.17173.com/playlist_30557988.html
http://v.17173.com/playlist_30558103.html
http://v.17173.com/playlist_30558153.html
http://v.17173.com/playlist_30558116.html
http://v.17173.com/playlist_30558154.html
http://v.17173.com/playlist_30558241.html
http://v.17173.com/playlist_30558271.html
http://v.17173.com/playlist_30558279.html
http://v.17173.com/playlist_30558286.html
http://v.17173.com/playlist_30558302.html
http://v.17173.com/playlist_30558296.html
http://v.17173.com/playlist_30558337.html
http://v.17173.com/playlist_30558400.html
http://v.17173.com/playlist_30558434.html
http://v.17173.com/playlist_30558410.html
http://v.17173.com/playlist_30558550.html
http://v.17173.com/playlist_30558569.html
http://v.17173.com/playlist_30558549.html
http://v.17173.com/playlist_30558516.html
http://v.17173.com/playlist_30558571.html
http://v.17173.com/playlist_30558614.html
http://v.17173.com/playlist_30558596.html
http://v.17173.com/playlist_30558648.html
http://v.17173.com/playlist_30558696.html
http://v.17173.com/playlist_30558779.html
http://v.17173.com/playlist_30558791.html
http://v.17173.com/playlist_30558826.html
http://v.17173.com/playlist_30558773.html
http://v.17173.com/playlist_30558837.html
http://v.17173.com/playlist_30558829.html
http://v.17173.com/playlist_30558832.html
http://v.17173.com/playlist_30558945.html
http://v.17173.com/playlist_30558928.html
http://v.17173.com/playlist_30558932.html
http://v.17173.com/playlist_30558995.html
http://v.17173.com/playlist_30559049.html
http://v.17173.com/playlist_30559067.html
http://v.17173.com/playlist_30559066.html
http://v.17173.com/playlist_30559070.html
http://v.17173.com/playlist_30559101.html
http://v.17173.com/playlist_30559094.html
http://v.17173.com/playlist_30559187.html
http://v.17173.com/playlist_30559167.html
http://v.17173.com/playlist_30559240.html
http://v.17173.com/playlist_30559209.html
http://v.17173.com/playlist_30559291.html
http://v.17173.com/playlist_30559326.html
http://v.17173.com/playlist_30559313.html
http://v.17173.com/playlist_30559334.html
http://v.17173.com/playlist_30559319.html
http://v.17173.com/playlist_30559406.html
http://v.17173.com/playlist_30559441.html
http://v.17173.com/playlist_30559465.html
http://v.17173.com/playlist_30559496.html
http://v.17173.com/playlist_30559478.html
http://v.17173.com/playlist_30559593.html
http://v.17173.com/playlist_30559590.html
http://v.17173.com/playlist_30559610.html
http://v.17173.com/playlist_30559606.html
http://v.17173.com/playlist_30559689.html
http://v.17173.com/playlist_30559719.html
http://v.17173.com/playlist_30559730.html
http://v.17173.com/playlist_30559742.html
http://v.17173.com/playlist_30559768.html
http://v.17173.com/playlist_30559795.html
http://v.17173.com/playlist_30559841.html
http://v.17173.com/playlist_30559854.html
http://v.17173.com/playlist_30559850.html
http://v.17173.com/playlist_30559907.html
http://v.17173.com/playlist_30559926.html
http://v.17173.com/playlist_30560026.html
http://v.17173.com/playlist_30560001.html
http://v.17173.com/playlist_30560054.html
http://v.17173.com/playlist_30560004.html
http://v.17173.com/playlist_30560087.html
http://v.17173.com/playlist_30560162.html
http://v.17173.com/playlist_30560168.html
http://v.17173.com/playlist_30560190.html
http://v.17173.com/playlist_30560206.html
http://v.17173.com/playlist_30560253.html
http://v.17173.com/playlist_30560256.html
http://v.17173.com/playlist_30560304.html
http://v.17173.com/playlist_30560312.html
http://v.17173.com/playlist_30560309.html
http://v.17173.com/playlist_30560416.html
http://v.17173.com/playlist_30560414.html
http://v.17173.com/playlist_30560513.html
http://v.17173.com/playlist_30560462.html
http://v.17173.com/playlist_30560491.html
http://v.17173.com/playlist_30560581.html
http://v.17173.com/playlist_30560545.html
http://v.17173.com/playlist_30560575.html
http://v.17173.com/playlist_30560605.html
http://v.17173.com/playlist_30560648.html
http://v.17173.com/playlist_30560656.html
http://v.17173.com/playlist_30560705.html
http://v.17173.com/playlist_30560759.html
http://v.17173.com/playlist_30560756.html
http://v.17173.com/playlist_30560818.html
http://v.17173.com/playlist_30560845.html
http://v.17173.com/playlist_30560841.html
http://v.17173.com/playlist_30560905.html
http://v.17173.com/playlist_30560875.html
http://v.17173.com/playlist_30560873.html
http://v.17173.com/playlist_30560934.html
http://v.17173.com/playlist_30560980.html
http://v.17173.com/playlist_30561033.html
http://v.17173.com/playlist_30561046.html
http://v.17173.com/playlist_30561099.html
http://v.17173.com/playlist_30561136.html
http://v.17173.com/playlist_30561150.html
http://v.17173.com/playlist_30561186.html
http://v.17173.com/playlist_30561214.html
http://v.17173.com/playlist_30561207.html
http://v.17173.com/playlist_30561216.html
http://v.17173.com/playlist_30561321.html
http://v.17173.com/playlist_30561365.html
http://v.17173.com/playlist_30561400.html
http://v.17173.com/playlist_30561437.html
http://v.17173.com/playlist_30561453.html
http://v.17173.com/playlist_30561523.html
http://v.17173.com/playlist_30561509.html
http://v.17173.com/playlist_30561537.html
http://v.17173.com/playlist_30561549.html
http://v.17173.com/playlist_30561661.html
http://v.17173.com/playlist_30561650.html
http://v.17173.com/playlist_30561680.html
http://v.17173.com/playlist_30561736.html
http://v.17173.com/playlist_30561825.html
http://v.17173.com/playlist_30561879.html
http://v.17173.com/playlist_30561876.html
http://v.17173.com/playlist_30561906.html
http://v.17173.com/playlist_30561911.html
http://v.17173.com/playlist_30561935.html
http://v.17173.com/playlist_30562015.html
http://v.17173.com/playlist_30562030.html
http://v.17173.com/playlist_30562052.html
http://v.17173.com/playlist_30562170.html
http://v.17173.com/playlist_30562169.html
http://v.17173.com/playlist_30562241.html
http://v.17173.com/playlist_30562243.html
http://v.17173.com/playlist_30562237.html
http://v.17173.com/playlist_30562272.html
http://v.17173.com/playlist_30562284.html
http://v.17173.com/playlist_30562302.html
http://v.17173.com/playlist_30562375.html
http://v.17173.com/playlist_30562372.html
http://v.17173.com/playlist_30562523.html
http://v.17173.com/playlist_30562552.html
http://v.17173.com/playlist_30562584.html
http://v.17173.com/playlist_30562574.html
http://v.17173.com/playlist_30562627.html
http://v.17173.com/playlist_30562610.html
http://v.17173.com/playlist_30562632.html
http://v.17173.com/playlist_30562677.html
http://v.17173.com/playlist_30562689.html
http://v.17173.com/playlist_30562690.html
http://v.17173.com/playlist_30562838.html
http://v.17173.com/playlist_30562897.html
http://v.17173.com/playlist_30562901.html
http://v.17173.com/playlist_30562910.html
http://v.17173.com/playlist_30562980.html
http://v.17173.com/playlist_30562971.html
http://v.17173.com/playlist_30562977.html
http://v.17173.com/playlist_30563004.html
http://v.17173.com/playlist_30563024.html
http://v.17173.com/playlist_30563063.html
http://v.17173.com/playlist_30563156.html
http://v.17173.com/playlist_30563189.html
http://v.17173.com/playlist_30563224.html
http://v.17173.com/playlist_30563266.html
http://v.17173.com/playlist_30563306.html
http://v.17173.com/playlist_30563311.html
http://v.17173.com/playlist_30563303.html
http://v.17173.com/playlist_30563358.html
http://v.17173.com/playlist_30563352.html
http://v.17173.com/playlist_30563354.html
http://v.17173.com/playlist_30563483.html
http://v.17173.com/playlist_30563549.html
http://v.17173.com/playlist_30563555.html
http://v.17173.com/playlist_30563605.html
http://v.17173.com/playlist_30563609.html
http://v.17173.com/playlist_30563638.html
http://v.17173.com/playlist_30563620.html
http://v.17173.com/playlist_30563634.html
http://v.17173.com/playlist_30563635.html
http://v.17173.com/playlist_30563637.html
http://v.17173.com/playlist_30563742.html
http://v.17173.com/playlist_30563816.html
http://v.17173.com/playlist_30563872.html
http://v.17173.com/playlist_30563906.html
http://v.17173.com/playlist_30563882.html
http://v.17173.com/playlist_30563921.html
http://v.17173.com/playlist_30563907.html
http://v.17173.com/playlist_30563956.html
http://v.17173.com/playlist_30563946.html
http://v.17173.com/playlist_30563985.html
http://v.17173.com/playlist_30564050.html
http://v.17173.com/playlist_30564119.html
http://v.17173.com/playlist_30564180.html
http://v.17173.com/playlist_30564245.html
http://v.17173.com/playlist_30564253.html
http://v.17173.com/playlist_30564258.html
http://v.17173.com/playlist_30564256.html
http://v.17173.com/playlist_30564287.html
http://v.17173.com/playlist_30564315.html
http://v.17173.com/playlist_30564333.html
http://v.17173.com/playlist_30564419.html
http://v.17173.com/playlist_30564435.html
http://v.17173.com/playlist_30564522.html
http://v.17173.com/playlist_30564562.html
http://v.17173.com/playlist_30564544.html
http://v.17173.com/playlist_30564581.html
http://v.17173.com/playlist_30564555.html
http://v.17173.com/playlist_30564586.html
http://v.17173.com/playlist_30564636.html
http://v.17173.com/playlist_30564624.html
http://v.17173.com/playlist_30564730.html
http://v.17173.com/playlist_30564828.html
http://v.17173.com/playlist_30564852.html
http://v.17173.com/playlist_30564830.html
http://v.17173.com/playlist_30564850.html
http://v.17173.com/playlist_30564871.html
http://v.17173.com/playlist_30564933.html
http://v.17173.com/playlist_30564905.html
http://v.17173.com/playlist_30564911.html
http://v.17173.com/playlist_30564940.html
http://v.17173.com/playlist_30565082.html
http://v.17173.com/playlist_30565149.html
http://v.17173.com/playlist_30565158.html
http://v.17173.com/playlist_30565215.html
http://v.17173.com/playlist_30565248.html
http://v.17173.com/playlist_30565236.html
http://v.17173.com/playlist_30565265.html
http://v.17173.com/playlist_30565274.html
http://v.17173.com/playlist_30565313.html
http://v.17173.com/playlist_30565323.html
http://v.17173.com/playlist_30565415.html
http://v.17173.com/playlist_30565455.html
http://v.17173.com/playlist_30565481.html
http://v.17173.com/playlist_30565565.html
http://v.17173.com/playlist_30565570.html
http://v.17173.com/playlist_30565574.html
http://v.17173.com/playlist_30565612.html
http://v.17173.com/playlist_30565624.html
http://v.17173.com/playlist_30565664.html
http://v.17173.com/playlist_30565665.html
http://v.17173.com/playlist_30565781.html
http://v.17173.com/playlist_30565751.html
http://v.17173.com/playlist_30565839.html
http://v.17173.com/playlist_30565875.html
http://v.17173.com/playlist_30565894.html
http://v.17173.com/playlist_30565897.html
http://v.17173.com/playlist_30565902.html
http://v.17173.com/playlist_30565892.html
http://v.17173.com/playlist_30565922.html
http://v.17173.com/playlist_30565937.html
http://v.17173.com/playlist_30566073.html
http://v.17173.com/playlist_30566074.html
http://v.17173.com/playlist_30566160.html
http://v.17173.com/playlist_30566191.html
http://v.17173.com/playlist_30566205.html
http://v.17173.com/playlist_30566240.html
http://v.17173.com/playlist_30566222.html
http://v.17173.com/playlist_30566270.html
http://v.17173.com/playlist_30566288.html
http://v.17173.com/playlist_30566319.html
http://v.17173.com/playlist_30566407.html
http://v.17173.com/playlist_30566428.html
http://v.17173.com/playlist_30566529.html
http://v.17173.com/playlist_30566530.html
http://v.17173.com/playlist_30566533.html
http://v.17173.com/playlist_30566523.html
http://v.17173.com/playlist_30566539.html
http://v.17173.com/playlist_30566643.html
http://v.17173.com/playlist_30566641.html
http://v.17173.com/playlist_30566667.html
http://v.17173.com/playlist_30566720.html
http://v.17173.com/playlist_30566740.html
http://v.17173.com/playlist_30566845.html
http://v.17173.com/playlist_30566852.html
http://v.17173.com/playlist_30566872.html
http://v.17173.com/playlist_30566877.html
http://v.17173.com/playlist_30566844.html
http://v.17173.com/playlist_30566956.html
http://v.17173.com/playlist_30566951.html
http://v.17173.com/playlist_30567011.html
http://v.17173.com/playlist_30567065.html
http://v.17173.com/playlist_30567076.html
http://v.17173.com/playlist_30567164.html
http://v.17173.com/playlist_30567200.html
http://v.17173.com/playlist_30567209.html
http://v.17173.com/playlist_30567286.html
http://v.17173.com/playlist_30567239.html
http://v.17173.com/playlist_30567259.html
http://v.17173.com/playlist_30567356.html
http://v.17173.com/playlist_30567394.html
http://v.17173.com/playlist_30567425.html
http://v.17173.com/playlist_30567429.html
http://v.17173.com/playlist_30567464.html
http://v.17173.com/playlist_30567551.html
http://v.17173.com/playlist_30567571.html
http://v.17173.com/playlist_30567610.html
http://v.17173.com/playlist_30567628.html
http://v.17173.com/playlist_30567644.html
http://v.17173.com/playlist_30567736.html
http://v.17173.com/playlist_30567731.html
http://v.17173.com/playlist_30567811.html
http://v.17173.com/playlist_30567814.html
http://v.17173.com/playlist_30567840.html
http://v.17173.com/playlist_30567888.html
http://v.17173.com/playlist_30567912.html
http://v.17173.com/playlist_30567943.html
http://v.17173.com/playlist_30567967.html
http://v.17173.com/playlist_30567958.html
http://v.17173.com/playlist_30568072.html
http://v.17173.com/playlist_30568130.html
http://v.17173.com/playlist_30568126.html
http://v.17173.com/playlist_30568137.html
http://v.17173.com/playlist_30568243.html
http://v.17173.com/playlist_30568220.html
http://v.17173.com/playlist_30568276.html
http://v.17173.com/playlist_30568285.html
http://v.17173.com/playlist_30568288.html
http://v.17173.com/playlist_30568326.html
http://v.17173.com/playlist_30568449.html
http://v.17173.com/playlist_30568465.html
http://v.17173.com/playlist_30568486.html
http://v.17173.com/playlist_30568530.html
http://v.17173.com/playlist_30568559.html
http://v.17173.com/playlist_30568613.html
http://v.17173.com/playlist_30568583.html
http://v.17173.com/playlist_30568611.html
http://v.17173.com/playlist_30568590.html
http://v.17173.com/playlist_30568658.html
http://v.17173.com/playlist_30568852.html
http://v.17173.com/playlist_30568866.html
http://v.17173.com/playlist_30568869.html
http://v.17173.com/playlist_30568901.html
http://v.17173.com/playlist_30568931.html
http://v.17173.com/playlist_30568966.html
http://v.17173.com/playlist_30568988.html
http://v.17173.com/playlist_30569000.html
http://v.17173.com/playlist_30569051.html
http://v.17173.com/playlist_30569121.html
http://v.17173.com/playlist_30569200.html
http://v.17173.com/playlist_30569248.html
http://v.17173.com/playlist_30569249.html
http://v.17173.com/playlist_30569285.html
http://v.17173.com/playlist_30569287.html
http://v.17173.com/playlist_30569307.html
http://v.17173.com/playlist_30569324.html
http://v.17173.com/playlist_30569326.html
http://v.17173.com/playlist_30569380.html
http://v.17173.com/playlist_30569463.html
http://v.17173.com/playlist_30569498.html
http://v.17173.com/playlist_30569549.html
http://v.17173.com/playlist_30569590.html
http://v.17173.com/playlist_30569595.html
http://v.17173.com/playlist_30569584.html
http://v.17173.com/playlist_30569635.html
http://v.17173.com/playlist_30569644.html
http://v.17173.com/playlist_30569673.html
http://v.17173.com/playlist_30569680.html
http://v.17173.com/playlist_30569788.html
http://v.17173.com/playlist_30569841.html
http://v.17173.com/playlist_30569911.html
http://v.17173.com/playlist_30569948.html
http://v.17173.com/playlist_30569962.html
http://v.17173.com/playlist_30569947.html
http://v.17173.com/playlist_30569950.html
http://v.17173.com/playlist_30570009.html
http://v.17173.com/playlist_30570028.html
http://v.17173.com/playlist_30570053.html
http://v.17173.com/playlist_30570240.html
http://v.17173.com/playlist_30570237.html
http://v.17173.com/playlist_30570288.html
http://v.17173.com/playlist_30570318.html
http://v.17173.com/playlist_30570364.html
http://v.17173.com/playlist_30570368.html
http://v.17173.com/playlist_30570378.html
http://v.17173.com/playlist_30570395.html
http://v.17173.com/playlist_30570413.html
http://v.17173.com/playlist_30570431.html
http://v.17173.com/playlist_30570584.html
http://v.17173.com/playlist_30570610.html
http://v.17173.com/playlist_30570625.html
http://v.17173.com/playlist_30570650.html
http://v.17173.com/playlist_30570695.html
http://v.17173.com/playlist_30570722.html
http://v.17173.com/playlist_30570728.html
http://v.17173.com/playlist_30570761.html
http://v.17173.com/playlist_30570798.html
http://v.17173.com/playlist_30570795.html
http://v.17173.com/playlist_30570938.html
http://v.17173.com/playlist_30570985.html
http://v.17173.com/playlist_30570987.html
http://v.17173.com/playlist_30571032.html
http://v.17173.com/playlist_30571075.html
http://v.17173.com/playlist_30571099.html
http://v.17173.com/playlist_30571134.html
http://v.17173.com/playlist_30571239.html
http://v.17173.com/playlist_30571219.html
http://v.17173.com/playlist_30571263.html
http://v.17173.com/playlist_30571345.html
http://v.17173.com/playlist_30571395.html
http://v.17173.com/playlist_30571448.html
http://v.17173.com/playlist_30571443.html
http://v.17173.com/playlist_30571499.html
http://v.17173.com/playlist_30571522.html
http://v.17173.com/playlist_30571588.html
http://v.17173.com/playlist_30571667.html
http://v.17173.com/playlist_30571671.html
http://v.17173.com/playlist_30571719.html
http://v.17173.com/playlist_30571804.html
http://v.17173.com/playlist_30571824.html
http://v.17173.com/playlist_30571856.html
http://v.17173.com/playlist_30571859.html
http://v.17173.com/playlist_30571920.html
http://v.17173.com/playlist_30571925.html
http://v.17173.com/playlist_30571936.html
http://v.17173.com/playlist_30572047.html
http://v.17173.com/playlist_30572068.html
http://v.17173.com/playlist_30572137.html
http://v.17173.com/playlist_30572160.html
http://v.17173.com/playlist_30572167.html
http://v.17173.com/playlist_30572237.html
http://v.17173.com/playlist_30572231.html
http://v.17173.com/playlist_30572314.html
http://v.17173.com/playlist_30572312.html
http://v.17173.com/playlist_30572332.html
http://v.17173.com/playlist_30572432.html
http://v.17173.com/playlist_30572578.html
http://v.17173.com/playlist_30572559.html
http://v.17173.com/playlist_30572591.html
http://v.17173.com/playlist_30572612.html
http://v.17173.com/playlist_30572669.html
http://v.17173.com/playlist_30572702.html
http://v.17173.com/playlist_30572738.html
http://v.17173.com/playlist_30572761.html
http://v.17173.com/playlist_30572802.html
http://v.17173.com/playlist_30572925.html
http://v.17173.com/playlist_30572978.html
http://v.17173.com/playlist_30573009.html
http://v.17173.com/playlist_30573001.html
http://v.17173.com/playlist_30573070.html
http://v.17173.com/playlist_30573095.html
http://v.17173.com/playlist_30573192.html
http://v.17173.com/playlist_30573173.html
http://v.17173.com/playlist_30573193.html
http://v.17173.com/playlist_30573278.html
http://v.17173.com/playlist_30573412.html
http://v.17173.com/playlist_30573452.html
http://v.17173.com/playlist_30573500.html
http://v.17173.com/playlist_30573519.html
http://v.17173.com/playlist_30573507.html
http://v.17173.com/playlist_30573546.html
http://v.17173.com/playlist_30573642.html
http://v.17173.com/playlist_30573646.html
http://v.17173.com/playlist_30573679.html
http://v.17173.com/playlist_30573797.html
http://v.17173.com/playlist_30573917.html
http://v.17173.com/playlist_30573948.html
http://v.17173.com/playlist_30573975.html
http://v.17173.com/playlist_30573985.html
http://v.17173.com/playlist_30574049.html
http://v.17173.com/playlist_30574120.html
http://v.17173.com/playlist_30574169.html
http://v.17173.com/playlist_30574194.html
http://v.17173.com/playlist_30574218.html
http://v.17173.com/playlist_30574363.html
http://v.17173.com/playlist_30574460.html
http://v.17173.com/playlist_30574473.html
http://v.17173.com/playlist_30574424.html
http://v.17173.com/playlist_30574546.html
http://v.17173.com/playlist_30574577.html
http://v.17173.com/playlist_30574695.html
http://v.17173.com/playlist_30574684.html
http://v.17173.com/playlist_30574725.html
http://v.17173.com/playlist_30574794.html
http://v.17173.com/playlist_30574905.html
http://v.17173.com/playlist_30574969.html
http://v.17173.com/playlist_30575014.html
http://v.17173.com/playlist_30574988.html
http://v.17173.com/playlist_30575064.html
http://v.17173.com/playlist_30575081.html
http://v.17173.com/playlist_30575192.html
http://v.17173.com/playlist_30575241.html
http://v.17173.com/playlist_30575233.html
http://v.17173.com/playlist_30575311.html
http://v.17173.com/playlist_30575467.html
http://v.17173.com/playlist_30575503.html
http://v.17173.com/playlist_30575563.html
http://v.17173.com/playlist_30575580.html
http://v.17173.com/playlist_30575668.html
http://v.17173.com/playlist_30575679.html
http://v.17173.com/playlist_30575727.html
http://v.17173.com/playlist_30575753.html
http://v.17173.com/playlist_30575849.html
http://v.17173.com/playlist_30575874.html
http://v.17173.com/playlist_30576025.html
http://v.17173.com/playlist_30576094.html
http://v.17173.com/playlist_30576127.html
http://v.17173.com/playlist_30576174.html
http://v.17173.com/playlist_30576207.html
http://v.17173.com/playlist_30576237.html
http://v.17173.com/playlist_30576270.html
http://v.17173.com/playlist_30576338.html
http://v.17173.com/playlist_30576425.html
http://v.17173.com/playlist_30576461.html
http://v.17173.com/playlist_30576611.html
http://v.17173.com/playlist_30576691.html
http://v.17173.com/playlist_30576723.html
http://v.17173.com/playlist_30576772.html
http://v.17173.com/playlist_30576774.html
http://v.17173.com/playlist_30576810.html
http://v.17173.com/playlist_30576839.html
http://v.17173.com/playlist_30576899.html
http://v.17173.com/playlist_30576990.html
http://v.17173.com/playlist_30577034.html
http://v.17173.com/playlist_30577184.html
http://v.17173.com/playlist_30577274.html
http://v.17173.com/playlist_30577293.html
http://v.17173.com/playlist_30577355.html
http://v.17173.com/playlist_30577350.html
http://v.17173.com/playlist_30577403.html
http://v.17173.com/playlist_30577410.html
http://v.17173.com/playlist_30577545.html
http://v.17173.com/playlist_30577535.html
http://v.17173.com/playlist_30577623.html
http://v.17173.com/playlist_30577734.html
http://v.17173.com/playlist_30577793.html
http://v.17173.com/playlist_30577830.html
http://v.17173.com/playlist_30577881.html
http://v.17173.com/playlist_30577848.html
http://v.17173.com/playlist_30577942.html
http://v.17173.com/playlist_30577922.html
http://v.17173.com/playlist_30578089.html
http://v.17173.com/playlist_30578100.html
http://v.17173.com/playlist_30578166.html
http://v.17173.com/playlist_30578237.html
http://v.17173.com/playlist_30578266.html
http://v.17173.com/playlist_30578289.html
http://v.17173.com/playlist_30578327.html
http://v.17173.com/playlist_30578355.html
http://v.17173.com/playlist_30578362.html
http://v.17173.com/playlist_30578371.html
http://v.17173.com/playlist_30578445.html
http://v.17173.com/playlist_30578487.html
http://v.17173.com/playlist_30578519.html
http://v.17173.com/playlist_30578537.html
http://v.17173.com/playlist_30578576.html
http://v.17173.com/playlist_30578617.html
http://v.17173.com/playlist_30578612.html
http://v.17173.com/playlist_30578635.html
http://v.17173.com/playlist_30578669.html
http://v.17173.com/playlist_30578666.html
http://v.17173.com/playlist_30578729.html
http://v.17173.com/playlist_30578790.html
http://v.17173.com/playlist_30578837.html
http://v.17173.com/playlist_30578881.html
http://v.17173.com/playlist_30578920.html
http://v.17173.com/playlist_30578941.html
http://v.17173.com/playlist_30578955.html
http://v.17173.com/playlist_30578969.html
http://v.17173.com/playlist_30579012.html
http://v.17173.com/playlist_30579043.html
http://v.17173.com/playlist_30579033.html
http://v.17173.com/playlist_30579085.html
http://v.17173.com/playlist_30579176.html
http://v.17173.com/playlist_30579218.html
http://v.17173.com/playlist_30579236.html
http://v.17173.com/playlist_30579244.html
http://v.17173.com/playlist_30579264.html
http://v.17173.com/playlist_30579271.html
http://v.17173.com/playlist_30579309.html
http://v.17173.com/playlist_30579343.html
http://v.17173.com/playlist_30579393.html
http://v.17173.com/playlist_30579404.html
http://v.17173.com/playlist_30579474.html
http://v.17173.com/playlist_30579507.html
http://v.17173.com/playlist_30579531.html
http://v.17173.com/playlist_30579545.html
http://v.17173.com/playlist_30579567.html
http://v.17173.com/playlist_30579582.html
http://v.17173.com/playlist_30579624.html
http://v.17173.com/playlist_30579643.html
http://v.17173.com/playlist_30579696.html
http://v.17173.com/playlist_30579697.html
http://v.17173.com/playlist_30579755.html
http://v.17173.com/playlist_30579775.html
http://v.17173.com/playlist_30579766.html
http://v.17173.com/playlist_30579807.html
http://v.17173.com/playlist_30579822.html
http://v.17173.com/playlist_30579856.html
http://v.17173.com/playlist_30579878.html
http://v.17173.com/playlist_30579902.html
http://v.17173.com/playlist_30579980.html
http://v.17173.com/playlist_30579992.html
http://v.17173.com/playlist_30580031.html
http://v.17173.com/playlist_30580067.html
http://v.17173.com/playlist_30580064.html
http://v.17173.com/playlist_30580082.html
http://v.17173.com/playlist_30580120.html
http://v.17173.com/playlist_30580167.html
http://v.17173.com/playlist_30580180.html
http://v.17173.com/playlist_30580195.html
http://v.17173.com/playlist_30580246.html
http://v.17173.com/playlist_30580247.html
http://v.17173.com/playlist_30580316.html
http://v.17173.com/playlist_30580342.html
http://v.17173.com/playlist_30580364.html
http://v.17173.com/playlist_30580361.html
http://v.17173.com/playlist_30580387.html
http://v.17173.com/playlist_30580431.html
http://v.17173.com/playlist_30580461.html
http://v.17173.com/playlist_30580488.html
http://v.17173.com/playlist_30580502.html
http://v.17173.com/playlist_30580541.html
http://v.17173.com/playlist_30580559.html
http://v.17173.com/playlist_30580580.html
http://v.17173.com/playlist_30580600.html
http://v.17173.com/playlist_30580611.html
http://v.17173.com/playlist_30580670.html
http://v.17173.com/playlist_30580727.html
http://v.17173.com/playlist_30580766.html
http://v.17173.com/playlist_30580784.html
http://v.17173.com/playlist_30580795.html
http://v.17173.com/playlist_30580829.html
http://v.17173.com/playlist_30580866.html
http://v.17173.com/playlist_30580886.html
http://v.17173.com/playlist_30580903.html
http://v.17173.com/playlist_30580914.html
http://v.17173.com/playlist_30580987.html
http://v.17173.com/playlist_30581047.html
http://v.17173.com/playlist_30581087.html
http://v.17173.com/playlist_30581105.html
http://v.17173.com/playlist_30581131.html
http://v.17173.com/playlist_30581167.html
http://v.17173.com/playlist_30581171.html
http://v.17173.com/playlist_30581163.html
http://v.17173.com/playlist_30581179.html
http://v.17173.com/playlist_30581195.html
http://v.17173.com/playlist_30581261.html
http://v.17173.com/playlist_30581335.html
http://v.17173.com/playlist_30581364.html
http://v.17173.com/playlist_30581389.html
http://v.17173.com/playlist_30581405.html
http://v.17173.com/playlist_30581434.html
http://v.17173.com/playlist_30581444.html
http://v.17173.com/playlist_30581447.html
http://v.17173.com/playlist_30581471.html
http://v.17173.com/playlist_30581492.html
http://v.17173.com/playlist_30581576.html
http://v.17173.com/playlist_30581618.html
http://v.17173.com/playlist_30581663.html
http://v.17173.com/playlist_30581688.html
http://v.17173.com/playlist_30581705.html
http://v.17173.com/playlist_30581723.html
http://v.17173.com/playlist_30581738.html
http://v.17173.com/playlist_30581734.html
http://v.17173.com/playlist_30581757.html
http://v.17173.com/playlist_30581793.html
http://v.17173.com/playlist_30581889.html
http://v.17173.com/playlist_30581926.html
http://v.17173.com/playlist_30581953.html
http://v.17173.com/playlist_30581983.html
http://v.17173.com/playlist_30582017.html
http://v.17173.com/playlist_30582021.html
http://v.17173.com/playlist_30582040.html
http://v.17173.com/playlist_30582039.html
http://v.17173.com/playlist_30582056.html
http://v.17173.com/playlist_30582078.html
http://v.17173.com/playlist_30582146.html
http://v.17173.com/playlist_30582179.html
http://v.17173.com/playlist_30582223.html
http://v.17173.com/playlist_30582269.html
http://v.17173.com/playlist_30582276.html
http://v.17173.com/playlist_30582288.html
http://v.17173.com/playlist_30582334.html
http://v.17173.com/playlist_30582355.html
http://v.17173.com/playlist_30582362.html
http://v.17173.com/playlist_30582392.html
http://v.17173.com/playlist_30582443.html
http://v.17173.com/playlist_30582455.html
http://v.17173.com/playlist_30582514.html
http://v.17173.com/playlist_30582541.html
http://v.17173.com/playlist_30582543.html
http://v.17173.com/playlist_30582594.html
http://v.17173.com/playlist_30582613.html
http://v.17173.com/playlist_30582622.html
http://v.17173.com/playlist_30582663.html
http://v.17173.com/playlist_30582690.html
http://v.17173.com/playlist_30582733.html
http://v.17173.com/playlist_30582740.html
http://v.17173.com/playlist_30582785.html
http://v.17173.com/playlist_30582796.html
http://v.17173.com/playlist_30582802.html
http://v.17173.com/playlist_30582853.html
http://v.17173.com/playlist_30582891.html
http://v.17173.com/playlist_30582893.html
http://v.17173.com/playlist_30582929.html
http://v.17173.com/playlist_30582955.html
http://v.17173.com/playlist_30583021.html
http://v.17173.com/playlist_30583048.html
http://v.17173.com/playlist_30583075.html
http://v.17173.com/playlist_30583089.html
http://v.17173.com/playlist_30583095.html
http://v.17173.com/playlist_30583132.html
http://v.17173.com/playlist_30583165.html
http://v.17173.com/playlist_30583164.html
http://v.17173.com/playlist_30583210.html
http://v.17173.com/playlist_30583255.html
http://v.17173.com/playlist_30583286.html
http://v.17173.com/playlist_30583315.html
http://v.17173.com/playlist_30583338.html
http://v.17173.com/playlist_30583350.html
http://v.17173.com/playlist_30583381.html
http://v.17173.com/playlist_30583370.html
http://v.17173.com/playlist_30583414.html
http://v.17173.com/playlist_30583417.html
http://v.17173.com/playlist_30583509.html
http://v.17173.com/playlist_30583525.html
http://v.17173.com/playlist_30583559.html
http://v.17173.com/playlist_30583572.html
http://v.17173.com/playlist_30583593.html
http://v.17173.com/playlist_30583637.html
http://v.17173.com/playlist_30583641.html
http://v.17173.com/playlist_30583635.html
http://v.17173.com/playlist_30583703.html
http://v.17173.com/playlist_30583722.html
http://v.17173.com/playlist_30583792.html
http://v.17173.com/playlist_30583799.html
http://v.17173.com/playlist_30583832.html
http://v.17173.com/playlist_30583848.html
http://v.17173.com/playlist_30583879.html
http://v.17173.com/playlist_30583911.html
http://v.17173.com/playlist_30583920.html
http://v.17173.com/playlist_30583955.html
http://v.17173.com/playlist_30583979.html
http://v.17173.com/playlist_30584000.html
http://v.17173.com/playlist_30584064.html
http://v.17173.com/playlist_30584088.html
http://v.17173.com/playlist_30584144.html
http://v.17173.com/playlist_30584127.html
http://v.17173.com/playlist_30584162.html
http://v.17173.com/playlist_30584179.html
http://v.17173.com/playlist_30584208.html
http://v.17173.com/playlist_30584226.html
http://v.17173.com/playlist_30584254.html
http://v.17173.com/playlist_30584275.html
http://v.17173.com/playlist_30584291.html
http://v.17173.com/playlist_30584374.html
http://v.17173.com/playlist_30584392.html
http://v.17173.com/playlist_30584399.html
http://v.17173.com/playlist_30584411.html
http://v.17173.com/playlist_30584442.html
http://v.17173.com/playlist_30584459.html
http://v.17173.com/playlist_30584492.html
http://v.17173.com/playlist_30584555.html
http://v.17173.com/playlist_30584578.html
http://v.17173.com/playlist_30584590.html
http://v.17173.com/playlist_30584630.html
http://v.17173.com/playlist_30584654.html
http://v.17173.com/playlist_30584655.html
http://v.17173.com/playlist_30584680.html
http://v.17173.com/playlist_30584753.html
http://v.17173.com/playlist_30584733.html
http://v.17173.com/playlist_30584782.html
http://v.17173.com/playlist_30584818.html
http://v.17173.com/playlist_30584842.html
http://v.17173.com/playlist_30584890.html
http://v.17173.com/playlist_30584912.html
http://v.17173.com/playlist_30584934.html
http://v.17173.com/playlist_30584941.html
http://v.17173.com/playlist_30584961.html
http://v.17173.com/playlist_30585002.html
http://v.17173.com/playlist_30585021.html
http://v.17173.com/playlist_30585063.html
http://v.17173.com/playlist_30585078.html
http://v.17173.com/playlist_30585085.html
http://v.17173.com/playlist_30585139.html
http://v.17173.com/playlist_30585202.html
http://v.17173.com/playlist_30585193.html
http://v.17173.com/playlist_30585192.html
http://v.17173.com/playlist_30585251.html
http://v.17173.com/playlist_30585248.html
http://v.17173.com/playlist_30585303.html
http://v.17173.com/playlist_30585329.html
http://v.17173.com/playlist_30585360.html
http://v.17173.com/playlist_30585403.html
http://v.17173.com/playlist_30585455.html
http://v.17173.com/playlist_30585482.html
http://v.17173.com/playlist_30585497.html
http://v.17173.com/playlist_30585520.html
http://v.17173.com/playlist_30585523.html
http://v.17173.com/playlist_30585524.html
http://v.17173.com/playlist_30585584.html
http://v.17173.com/playlist_30585571.html
http://v.17173.com/playlist_30585623.html
http://v.17173.com/playlist_30585686.html
http://v.17173.com/playlist_30585722.html
http://v.17173.com/playlist_30585788.html
http://v.17173.com/playlist_30585767.html
http://v.17173.com/playlist_30585790.html
http://v.17173.com/playlist_30585818.html
http://v.17173.com/playlist_30585809.html
http://v.17173.com/playlist_30585877.html
http://v.17173.com/playlist_30585907.html
http://v.17173.com/playlist_30585944.html
http://v.17173.com/playlist_30585946.html
http://v.17173.com/playlist_30585965.html
http://v.17173.com/playlist_30586040.html
http://v.17173.com/playlist_30586036.html
http://v.17173.com/playlist_30586042.html
http://v.17173.com/playlist_30586089.html
http://v.17173.com/playlist_30586081.html
http://v.17173.com/playlist_30586157.html
http://v.17173.com/playlist_30586189.html
http://v.17173.com/playlist_30586199.html
http://v.17173.com/playlist_30586238.html
http://v.17173.com/playlist_30586249.html
http://v.17173.com/playlist_30586287.html
http://v.17173.com/playlist_30586303.html
http://v.17173.com/playlist_30586313.html
http://v.17173.com/playlist_30586341.html
http://v.17173.com/playlist_30586326.html
http://v.17173.com/playlist_30586417.html
http://v.17173.com/playlist_30586431.html
http://v.17173.com/playlist_30586448.html
http://v.17173.com/playlist_30586484.html
http://v.17173.com/playlist_30586542.html
http://v.17173.com/playlist_30586554.html
http://v.17173.com/playlist_30586569.html
http://v.17173.com/playlist_30586621.html
http://v.17173.com/playlist_30586632.html
http://v.17173.com/playlist_30586652.html
http://v.17173.com/playlist_30586703.html


public class FlipCoin {
	public static void main(String[] args) {
		int[] A = {1, 1, 0, 1, 0, 0, 1, 1};
		System.out.println(new FlipCoin().solution(A) );
	}
		
	public int solution(int[] A) {
		boolean flipped = false;
		int adjacency = 0;
		for(int i=1; i<A.length-1; i++) {
			if(A[i] == A[i-1]) adjacency++;
			else if(A[i-1] == A[i+1] && !flipped) {
				flipped = true;
				adjacency += 2;
				i++;
			}
		}
		
		if(flipped ) {
			if(A[A.length-1] == A[A.length-2]) adjacency++;
		} else {
			if(A[A.length-1] != A[A.length-2]) adjacency++;
                        else if(A[0] != A[1] ) adjacency+=2; 
                }
		
		return adjacency;
	}
}


你可能感兴趣的:(Consider N coins aligned in a row.)