• + 0 comments

    this is my go solution, some extra lines maybe buy very good performance.

        cleanRanked := func(ranked []int32) []int32 {
            newRank := make([]int32, 0)
            for i := 0; i < len(ranked)-1; i++ {
                if ranked[i] != ranked[i+1] {
                    newRank = append(newRank, ranked[i])
                }
            }
            newRank = append(newRank, ranked[len(ranked)-1])
            return newRank
        }(ranked)
    
        j := 0
        var position int32 = 1
        positions := make([]int32, len(player))
    
        for i := len(player) - 1; i >= 0; i-- {
            for j <= len(cleanRanked)-1 && cleanRanked[j] > player[i] {
                if j == len(cleanRanked)-1 || cleanRanked[j] > cleanRanked[j+1] {
                    position++
                }
                j++
            }
            positions[i] = position
        }
    
        return positions
    }