Quick Sort Implementation

Sort a given array of integers in ascending order using the Quick Sort algorithm.

Quick Sort is a divide and conquer algorithm that involves selecting a pivot element and partitioning the array into two sub-arrays: one containing elements less than the pivot, and the other containing elements greater than the pivot. The sub-arrays are then sorted recursively.

Example:

Input:
array = [4, 2, 1, 5, 3]
Output:
[1, 2, 3, 4, 5]
Explanation:

After the first level of partitioning with 3 as pivot, the array becomes [2, 1, 3, 4, 5]. After the second level with 1 as pivot on the left and 5 on the right, the sorted array is [1, 2, 3, 4, 5].

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 103
  • -109 ≤ ARR[i] ≤ 109
  • The input contains T test cases, where each test case consists of an integer N and an array ARR with N elements.
  • Time limit: 1 second.

Note: You do not need to print anything; just implement the function as required.

AnswerBot
1y

Implement Quick Sort to sort an array of integers in ascending order.

  • Choose a pivot element from the array

  • Partition the array into two parts: elements smaller than the pivot and elements larger than t...read more

Help your peers!
Select
Add answer anonymously...

Protium Finance Software Developer interview questions & answers

A Software Developer was asked Q. Search In Rotated Sorted Array Problem Statement Given a sorted array of distinc...read more
A Software Developer was asked Q. What is the garbage collector in Java?
A Software Developer was asked Q. What is the difference between an abstract class and an interface in Object-Orie...read more

Popular interview questions of Software Developer

A Software Developer was asked Q1. Search In Rotated Sorted Array Problem Statement Given a sorted array of distinc...read more
A Software Developer was asked Q2. What is the garbage collector in Java?
A Software Developer was asked Q3. What is the difference between an abstract class and an interface in Object-Orie...read more
Protium Finance Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits