Skip to content

Commit

Permalink
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Arrays: New Year …
Browse files Browse the repository at this point in the history
…Chaos. Clean code: no magic numbers.
  • Loading branch information
Gonzalo Diaz committed Mar 1, 2025
1 parent 838c56b commit df9056e
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

//nolint:stylecheck // error strings should not be capitalized (ST1005)
const tooChaoticError = "Too chaotic"
const NEW_YEAR_CHAOS_TOLERANCE = 2

func minimumBribesCalculate(q []int32) (int32, error) {

Expand All @@ -21,12 +22,13 @@ func minimumBribesCalculate(q []int32) (int32, error) {
for _, value = range q {
position := i + 1

if value-int32(position) > 2 {
//nolint:stylecheck // error strings should not be capitalized (ST1005)
if value-int32(position) > NEW_YEAR_CHAOS_TOLERANCE {
// error strings should not be capitalized (ST1005)
//nolint:stylecheck
return 0, errors.New(tooChaoticError)
}

var fragment []int32 = q[min(max(value-2, 0), int32(i)):i]
var fragment []int32 = q[min(max(value-NEW_YEAR_CHAOS_TOLERANCE, 0), int32(i)):i]

for _, k := range fragment {
if k > value {
Expand Down

0 comments on commit df9056e

Please sign in to comment.