Question:
How to sort the array in ascending order using Python?

Summary

Let's assume:

Array- Arr

Integer- N

Function- sort012()


Solution

#User function Template for python3


class Solution:

    def sort012(self,arr,n):

        # code here

        low = 0

        mid = 0

        high = n - 1


        while mid <= high:

            if arr[mid] == 0:

                arr[low], arr[mid] = arr[mid], arr[low]

                low += 1

                mid += 1

            elif arr[mid] == 1:

                mid += 1

            else:

                arr[mid], arr[high] = arr[high], arr[mid]

                high -= 1


Suggested blogs:

>>How can I specify a monkey-patched class in the typescript definitions file in JavaScript?

>>How to merge an object into Array of an objects with the same key in JavaScript?

>>How to make one JavaScript event wait for another to trigger?

>>How to manipulate Array object in JavaScript?

>>How to do light and dark mode in a website using HTML and JavaScript?



Nisha Patel

Nisha Patel

Submit
0 Answers