Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6564 |

@blackshadows | 6400 |

@mb1973 | 5785 |

@Quandray | 5275 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5074 |

@kirtidee18 | 4639 |

@sanjay05 | 3762 |

@mantu_singh | 3712 |

@gfgaccount | 3627 |

@marius_valentin_dragoi | 3525 |

Complete Leaderboard | |

Handle | Score |

@yaswanthero123 | 625 |

@vikash619 | 611 |

@venkat11803610 | 501 |

@roshan13ar | 396 |

@DevangSingh | 379 |

@ravi11815721 | 312 |

@hrishipangavhane | 286 |

@aryanjain85297 | 280 |

@kommaraju11806903 | 277 |

@infosumitraut | 272 |

@sanalbabunb | 263 |

Complete Leaderboard |

Given a sorted integer array **Arr[ ]** of size **N**, and three integers **A**, **B,** and **C. **The task is to find a new array where **i ^{th}** element of the new array =

**Example 1:**

**Input:**
A = -1, B = 2, C = -1.
N = 6
Arr[] = {-1, 0, 1, 2, 3, 4}
**Output:**
-9 -4 -4 -1 -1 0
**Explanation: **After applying the equation
A * Arr[i] * Arr[i] + B * Arr[i] + C on every
element Arr[i] we get {-4, -1, 0, -1, -4, -9}.
After sorting, we get {-9, -4, -4, -1, -1, 0}.

**Example 2:**

**Input:**
A = 1, B = 1, C = 1.
N = 3
Arr[] = {1, 2, 3}
**Output:**
3 7 13
**Explanation: **After applying the equation
A * Arr[i] * Arr[i] + B * Arr[i] + C on every
element Arr[i] we get {3, 7, 13} which is
already sorted.

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **sortArray()** which takes **Arr[]**, **N, A, B **and** C**** **as input parameters and returns the sorted new list.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(N)

**Constraints:**

1 ≤ N ≤ 10^{6}

-10^{5} ≤ arr[i] ≤ 10^{5}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Sort the given array after applying the given equation

...