Interview - Find magnitude pole in an array

前端 未结 8 2249
孤独总比滥情好
孤独总比滥情好 2021-02-09 15:52

Magnitude Pole: An element in an array whose left hand side elements are lesser than or equal to it and whose right hand side element are greater than or equal to it.

8条回答
  •  余生分开走
    2021-02-09 16:31

    1. Create array of ints called mags, and int variable called maxMag.
    2. For each element in source array check if element is greater or equal to maxMag.
    3. If is: add element to mags array and set maxMag = element.
    4. If isn't: loop through mags array and remove all elements lesser.

    Result: array of magnitude poles

提交回复
热议问题