程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python implementation of Huawei machine test] tall and short people queue up

編輯:Python

List of articles

  • Preface
  • Title Description
  • Example 1
  • Example 2
  • Example 3
  • Reference code


Preface

《 Huawei machine test real problem 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 ).

See for detailed explanation 【 Detailed explanation of Huawei's machine test questions 】 Tall and short people line up

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 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved