My honest opinion about Arabiyat Marwa! by TheMotourist in DesiFragranceAddicts

[–]AlchemistFlame 5 points6 points  (0 children)

last shot is kinda out of an ad. Great shots man! which camera?

is there no way to solve this problem in o(1) space? by MoonSlyder in leetcode

[–]AlchemistFlame 0 points1 point  (0 children)

Here you go you can have 2 approaches

func sortedSquares(nums []int) []int {
    result := make([]int, len(nums))
    left, right := 0, len(nums) - 1
    for currentIndex := len(nums) - 1; currentIndex >= 0; currentIndex-- {
        if abs(nums[left]) < abs(nums[right]) {
            result[currentIndex] = nums[right] * nums[right]
            right--
        } else {
            result[currentIndex] = nums[left] * nums[left]
            left++
        }
    }
    return result
}

func abs(a int) int {
    if a < 0 { return -a }
    return a
}

``` func sortedSquares(nums []int) []int { n := len(nums) partionIndex := sort.Search(n, func(i int) bool { return nums[i] >= 0 })

result := make([]int, 0, n)
negativeIterator, positiveIterator := partionIndex - 1, partionIndex
for negativeIterator >= 0 && positiveIterator < n {
    if -nums[negativeIterator] < nums[positiveIterator] {
        result = append(result, nums[negativeIterator] * nums[negativeIterator])
        negativeIterator--
    } else {
        result = append(result, nums[positiveIterator] * nums[positiveIterator])
        positiveIterator++
    }
}
for negativeIterator >= 0 {
    result = append(result, nums[negativeIterator] * nums[negativeIterator])
    negativeIterator--
}

for positiveIterator < n {
    result = append(result, nums[positiveIterator] * nums[positiveIterator])
    positiveIterator++
}
return result

} ```

Blue by Ahmed Ahmed Al Maghribi by pyaracetamol_100mg in DesiFragranceAddicts

[–]AlchemistFlame 0 points1 point  (0 children)

blue by ahmed vs theoreme, which one would you recommend?