Facebook Question | LeetCode 977. Squares of a Sorted Array | Tamil | code io

preview_player
Показать описание
977. Squares of a Sorted Array

Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

Follow us on
Instagram

Linkedin

Keywords
Leetcode Solution
Interview Preparations
Google
Facebook
Meta
Google Interview
Facebook Interview
Рекомендации по теме
Комментарии
Автор

*JAVA SOLUTION 100% Runtime*
*Faster than Arrays.sort() function*
*Time Complexity -> O(n)*
*Space Complxity -> O(n)*
class Solution {
public int[] sortedSquares(int[] a) {
int length = a.length;
int[] ans = new int[length];
for(int i=0;i<length;i++) if(a[i] < 0) a[i] = -a[i];
int left = 0, right = length-1, index = length-1;
while(left<=right){
if(a[left] <= a[right]) ans[index--] = a[right]*a[right--];
else ans[index--] = a[left]*a[left++];
}
return ans;
}
}

-Corvo_Attano
Автор

Can you come up with o(n) time complexity?

aswins
Автор

Ni solve panuranthu Java program ra
Uses manirigala

gayathrigayathri
Автор

Bro programming beginners entha software bro use panrathu?

uniquekishore
visit shbcf.ru