LeetCode
Question
·
Jan 2025
Paypal SDE Interview
2 upvotes
548 views
1 reply
Question Details
Background- 3+ YoE
Round 1 technical Interview (in Golang)- Resume based questions were asked, based on the tech stack I had used and explanation of the tech stack I use in my...
Full Details
Background- 3+ YoE
Round 1 technical Interview (in Golang)-
Resume based questions were asked, based on the tech stack I had used and explanation of the tech stack I use in my project vs other options available.
Given an integer array, nums, sorted in non-decreasing order,
return an array of squares of each number sorted in non-decreasing order.
example:
nums={-4, -1, 0, 3, 10}
result {0, 1, 9, 16, 100}
code:
package main
import (
\t"fmt"
)
// left ptr, right ptr to start from beginning and end resp
// compute and compare the squares
// choose the lareger val and append to result.
func sortedSquare(nums []int) []int {
\tn := len(nums)
\tresult := make([]int, n)
\tl, r := 0, n-1
\tfor i := n - 1; i >= 0; i-- {
\t\tlSquare := nums[l] * nums[l]
\t\trSquare := nums[r] * nums[r]
\t\t// compute and compare
\t\tif lSquare > rSquare {
\t\t\tresult[i] = lSquare
\t\t\tl++
\t\t} else {
\t\t\tresult[i] = rSquare
\t\t\tr--
\t\t}
\t}
\treturn result
}
func main() {
\tnums1 := []int{-4, -1, 0, 3, 10} res = [0, 1, 9, 16, 100]
\tnums2 := []int{-8, -1, 0, 4, 7} // res = [0,1,16,49,64]
\tnums3 := []int{-10, 0, 1, 2, 11} // res = [0, 1, 4, 100, 121]
\tout1 := sortedSquare(nums1)
\tout2 := sortedSquare(nums2)
\tout3 := sortedSquare(nums3)
\tfmt.Println(out1)
\tfmt.Println(out2)
\tfmt.Println(out3)
}
Free preview. Unlock all Paypal questions →
About This Question
This is a reported interview question from a paypal interview for a swe role during the phone screen round reported in 2025.