当前位置:网站首页>[detailed explanation of Huawei machine test] tall and short people queue up

[detailed explanation of Huawei machine test] tall and short people queue up

2022-07-07 10:25:00 A less intelligent programmer


Preface

《 Detailed explanation of Huawei's machine test questions Python Realization 》 The column includes Huawei column of niuke.com 、 Huawei test questions 、 Huawei OD Real problem of machine test .

If you are preparing for Huawei's interview , If you want to know something, you can send me a private letter , I will try my best to help you , I can also give you some suggestions !

This paper solves the non optimal solution ( Non optimal performance ).

Title Description

Now there is a group of children , They are different in height , We express the height of this group of children in an array of positive integers , Such as arrays {5,3,1,2,3}.

Now we want the children to line up , With “ high ”“ Short ”“ high ”“ Short ” Sequential arrangement , every last “ high ” The position of the children should be higher than the adjacent position or equal ; every last “ Short ” The children in the position should be shorter than or equal to the adjacent position ;

Ask the children to move at a minimum distance , The first one from “ high ” Start to line up , Output the minimum moving distance .

for example , In the demonstration team {5,3,1,2,3} in ,{5, 1, 3, 2, 3} It's the sorting result .{5, 2, 3, 1, 3} Although also satisfied “ high ”“ Short ”“ high ”“ Short ” Sequential arrangement , But children move a lot , So it's not the best result .

The definition of moving distance is as follows :

The second child moves behind the third child 

原网站

版权声明
本文为[A less intelligent programmer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070800033699.html