Learning GoLang: Maximum Gap by justyy

View this thread on steempeak.com
· @justyy ·
$39.55
Learning GoLang: Maximum Gap
<blockquote>
Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains less than two elements, return 0.

 Example 1:

Input: nums = [3,6,9,1]
Output: 3
Explanation: The sorted form of the array is [1,3,6,9], either (3,6) or (6,9) has the maximum difference 3.
Example 2:

Input: nums = [10]
Output: 0
Explanation: The array contains less than 2 elements, therefore return 0.
 
Constraints:
1 <= nums.length <= 104
0 <= nums[i] <= 109
</blockquote>

GoLang Exercise as follows:

```
func maximumGap(nums []int) int {
    if len(nums) < 2 {
        return 0
    }
    var ans = 0
    sort.Ints(nums)
    for i := 1; i < len(nums); i ++ {
        ans = int(math.Max(float64(ans), float64(nums[i] - nums[i - 1])))
    }
    return ans
}
```

Time complexity is O(NLogN)


^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Thank you for reading ^^^^^^^^^^^^^^^
---------------
## NEW! [Following my Trail (Upvote or/and Downvote)](https://steemit.com/witness-category/@justyy/following-my-trail-upvote-or-and-downvote-by-authorizing-posting-key-to-me)


Follow me for topics of *Algorithms, Blockchain and Cloud.*
I am @justyy - a Steem Witness
[https://steemyy.com](https://steemyy.com)

#### My contributions
- [Video Downloader](https://weibomiaopai.com/download-video-parser.php)
- [Steem Blockchain Tools](https://steemyy.com)
- [Free Cryptos API](https://steemit.com/witness-category/@justyy/serverless-api-to-query-the-cryptos-and-fiat)
- [VPS Database](https://anothervps.com/vps-database/)
- [Computing Technology Blog](https://helloacm.com)
- [A few useless tools](https://helloacm.com/tools/)
- [And some other online software/tools](https://steakovercooked.com/Software.Home)
- [Merge Files/Videos](https://slowapi.com/merge-videos/)
- [LOGO Turtle Programming Chrome Extension](https://chrome.google.com/webstore/detail/logo-turtle-graphics/dcoeaobaokbccdcnadncifmconllpihp)
- [Teaching Kids Programming - Youtube Channel](https://www.youtube.com/channel/UCK2ugmUOoYne1qQfSAph4nQ?view_as=subscriber) and [All Contents](https://github.com/DoctorLai/Teaching-Kids-Programming/blob/main/README.md)

#### Delegation Service
1. [Voting Algorithm Updated to Favor those High Delegations!](https://steemit.com/wherein/@justyy/voting-algorithm-updated-to-favor-those-high-delegations)

- Delegate 1000 to justyy: [Link](https://steemyy.com/sp-delegate-form/?delegatee=justyy&amp;amount=1000)
- Delegate 5000 to justyy: [Link](https://steemyy.com/sp-delegate-form/?delegatee=justyy&amp;amount=5000)
- Delegate 10000 to justyy: [Link](https://steemyy.com/sp-delegate-form/?delegatee=justyy&amp;amount=10000)

#### Support me
If you like my work, please: 
- [Buy Me a Coffee](https://justyy.com/out/buymeacoffee), Thanks!
- [Become my Sponsor](https://github.com/sponsors/DoctorLai), Thanks!
- Voting for me:
https://steemit.com/~witnesses type in **justyy** and click ***VOTE***
https://steemyy.com/images/vote-for-justyy.jpg


1. Delegate SP: https://steemyy.com/sp-delegate-form/?delegatee=justyy
2. Vote @justyy as Witness:  https://steemyy.com/witness-voting/?witness=justyy&amp;action=approve
3. Set @justyy as Proxy: https://steemyy.com/witness-voting/?witness=justyy&amp;action=proxy
Alternatively, you can vote witness or set proxy here: https://steemit.com/~witnesses


-------------
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 166 others
πŸ‘Ž  
properties (23)
post_id91,564,855
authorjustyy
permlinklearning-golang-maximum-gap
categoryprogramming
json_metadata{"tags":["programming","golang","sct","blog","whalepower","coding","tutorial","upmefund"],"users":["justyy"],"image":["https:\/\/steemyy.com\/images\/vote-for-justyy.jpg"],"links":["https:\/\/steemit.com\/witness-category\/@justyy\/following-my-trail-upvote-or-and-downvote-by-authorizing-posting-key-to-me","https:\/\/steemyy.com","https:\/\/weibomiaopai.com\/download-video-parser.php","https:\/\/steemit.com\/witness-category\/@justyy\/serverless-api-to-query-the-cryptos-and-fiat","https:\/\/anothervps.com\/vps-database\/","https:\/\/helloacm.com","https:\/\/helloacm.com\/tools\/","https:\/\/steakovercooked.com\/Software.Home","https:\/\/slowapi.com\/merge-videos\/","https:\/\/chrome.google.com\/webstore\/detail\/logo-turtle-graphics\/dcoeaobaokbccdcnadncifmconllpihp","https:\/\/www.youtube.com\/channel\/UCK2ugmUOoYne1qQfSAph4nQ?view_as=subscriber","https:\/\/github.com\/DoctorLai\/Teaching-Kids-Programming\/blob\/main\/README.md","https:\/\/steemit.com\/wherein\/@justyy\/voting-algorithm-updated-to-favor-those-high-delegations","https:\/\/steemyy.com\/sp-delegate-form\/?delegatee=justyy&amp;amount=1000","https:\/\/steemyy.com\/sp-delegate-form\/?delegatee=justyy&amp;amount=5000","https:\/\/steemyy.com\/sp-delegate-form\/?delegatee=justyy&amp;amount=10000","https:\/\/justyy.com\/out\/buymeacoffee","https:\/\/github.com\/sponsors\/DoctorLai","https:\/\/steemit.com\/~witnesses","https:\/\/steemyy.com\/sp-delegate-form\/?delegatee=justyy","https:\/\/steemyy.com\/witness-voting\/?witness=justyy&amp;action=approve","https:\/\/steemyy.com\/witness-voting\/?witness=justyy&amp;action=proxy"],"app":"steemit\/0.2","format":"markdown"}
created2021-05-30 10:06:21
last_update2021-05-30 10:06:21
depth0
children2
net_rshares42,097,359,509,497
last_payout2021-06-06 10:06:21
cashout_time1969-12-31 23:59:59
total_payout_value22.298 SBD
curator_payout_value17.249 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length3,364
author_reputation2,010,635,440,258,493
root_title"Learning GoLang: Maximum Gap"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (231)
@coder-geek ·
Eventhough I don't know GoLang, I coould grasp the algorithm. I think I should try solving the same problem in Python. Would be a fun to do thatπŸ™‚.
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
πŸ‘Ž  
properties (23)
post_id91,576,894
authorcoder-geek
permlinkqtxtmn
categoryprogramming
json_metadata{"app":"steemit\/0.2"}
created2021-05-30 20:43:45
last_update2021-05-30 20:43:45
depth1
children1
net_rshares-584,318,468,854
last_payout2021-06-06 20:43:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length146
author_reputation24,799,586,776
root_title"Learning GoLang: Maximum Gap"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (62)
@justyy ·
Yes... i am learning Go recently...
properties (22)
post_id91,588,826
authorjustyy
permlinkqtyse6
categoryprogramming
json_metadata{"app":"steemit\/0.2"}
created2021-05-31 09:15:45
last_update2021-05-31 09:15:45
depth2
children0
net_rshares0
last_payout2021-06-07 09:15:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length35
author_reputation2,010,635,440,258,493
root_title"Learning GoLang: Maximum Gap"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000