{"id":23828555,"url":"https://github.com/waldohidalgo/coding-ninja-21-day-coding-challenge","last_synced_at":"2026-06-29T10:31:44.472Z","repository":{"id":267363926,"uuid":"897427817","full_name":"waldohidalgo/coding-ninja-21-day-coding-challenge","owner":"waldohidalgo","description":"Repositorio con el código solución a los desafíos diarios del 21-Day Coding Challenge: Ninja Slayground 2.0 de Coding Ninja","archived":false,"fork":false,"pushed_at":"2024-12-09T22:25:21.000Z","size":111,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-22T02:26:48.108Z","etag":null,"topics":["codingninjas","codingninjas-python-dsa"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/waldohidalgo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-02T16:01:27.000Z","updated_at":"2024-12-09T22:25:24.000Z","dependencies_parsed_at":"2024-12-09T23:24:58.033Z","dependency_job_id":"40387c98-1fe0-48b3-868b-08ca9d63102f","html_url":"https://github.com/waldohidalgo/coding-ninja-21-day-coding-challenge","commit_stats":null,"previous_names":["waldohidalgo/coding-ninja-21-day-coding-challenge"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/waldohidalgo/coding-ninja-21-day-coding-challenge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldohidalgo%2Fcoding-ninja-21-day-coding-challenge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldohidalgo%2Fcoding-ninja-21-day-coding-challenge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldohidalgo%2Fcoding-ninja-21-day-coding-challenge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldohidalgo%2Fcoding-ninja-21-day-coding-challenge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waldohidalgo","download_url":"https://codeload.github.com/waldohidalgo/coding-ninja-21-day-coding-challenge/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waldohidalgo%2Fcoding-ninja-21-day-coding-challenge/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34923763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-29T02:00:05.398Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codingninjas","codingninjas-python-dsa"],"created_at":"2025-01-02T13:18:40.557Z","updated_at":"2026-06-29T10:31:44.455Z","avatar_url":"https://github.com/waldohidalgo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 21-Day Coding Challenge: Ninja Slayground 2.0\n\nRepositorio con el código solución a los 21 desafíos diarios.\n\n## Tabla de Contenido\n\n- [21-Day Coding Challenge: Ninja Slayground 2.0](#21-day-coding-challenge-ninja-slayground-20)\n  - [Tabla de Contenido](#tabla-de-contenido)\n  - [Certificados Obtenidos](#certificados-obtenidos)\n    - [Certificado Participación](#certificado-participación)\n    - [Certificado Level 1: 7 days Streak](#certificado-level-1-7-days-streak)\n    - [Certificado Level 2: 14 days Streak](#certificado-level-2-14-days-streak)\n    - [Certificado Level 3: 21 days Streak](#certificado-level-3-21-days-streak)\n  - [Ejercicios Resueltos](#ejercicios-resueltos)\n    - [Day 1: Switch Case statement](#day-1-switch-case-statement)\n    - [Day 2: Nth Fibonacci Number](#day-2-nth-fibonacci-number)\n    - [Day 3: Number of digits](#day-3-number-of-digits)\n    - [Day 4: Prime Number](#day-4-prime-number)\n    - [Day 5: Check Sorted Array](#day-5-check-sorted-array)\n    - [Day 6: Reverse a Number](#day-6-reverse-a-number)\n    - [Day 7: Reverse an Array](#day-7-reverse-an-array)\n    - [Day 8: GCD or HCF](#day-8-gcd-or-hcf)\n    - [Day 9: Second Largest Number](#day-9-second-largest-number)\n    - [Day 10: Highest / Lowest Frequency Elements](#day-10-highest--lowest-frequency-elements)\n    - [Day 11: Two Sum](#day-11-two-sum)\n    - [Day 12: Add One To Number](#day-12-add-one-to-number)\n    - [Day 13: Binary Search](#day-13-binary-search)\n    - [Day 14: Sort An Array of 0s, 1s and 2s](#day-14-sort-an-array-of-0s-1s-and-2s)\n    - [Day 15: Implement Lower Bound](#day-15-implement-lower-bound)\n    - [Day 16: Valid Parentheses](#day-16-valid-parentheses)\n    - [Day 17: Implement Upper Bound](#day-17-implement-upper-bound)\n    - [Day 18: Spiral Matrix](#day-18-spiral-matrix)\n    - [Day 19: Zero Matrix](#day-19-zero-matrix)\n    - [Day 20: Pascal's Triangle](#day-20-pascals-triangle)\n    - [Day 21: Number of Inversions](#day-21-number-of-inversions)\n\n## Certificados Obtenidos\n\n### Certificado Participación\n\n![Certificado Participación](./certificados/certificado_participacion.webp)\n\n### Certificado Level 1: 7 days Streak\n\n![Certificado Level 1: 7 days Streak](./certificados/certificado_level1.webp)\n\n### Certificado Level 2: 14 days Streak\n\n![Certificado Level 2: 14 days Streak](./certificados/certificado_level2.webp)\n\n### Certificado Level 3: 21 days Streak\n\n![Certificado Level 3: 21 days Streak](./certificados/certificado_level3.webp)\n\n## Ejercicios Resueltos\n\n### Day 1: Switch Case statement\n\nIn a menu-driven program, the user is given a set of choices of things to do (the menu) and then is asked to select a menu item.\n\nThere are 2 choices in the menu:\n\nChoice 1 is to find the area of a circle having radius 'r'.\n\nChoice 2 is to find the area of a rectangle having dimensions 'l' and 'b'.\n\nYou are given the choice 'ch' and an array 'a'.\n\nIf ‘ch’ is 1, ‘a’ contains a single number ‘r’. If ‘ch’ is 2, ‘a’ contains 2 numbers, ‘l’ and ‘b’.\n\nConsider the choice and print the appropriate area.\n\n```py\nfrom typing import *\nfrom math import pi\ndef areaSwitchCase(ch: int, a: List[float]):\n    # Write your code here\n    if ch == 1:\n        return round(pi*a[0]**2,5)\n    elif ch == 2:\n        return f'{a[0] * a[1]:.5f}'\n    else:\n        return -1\n```\n\n### Day 2: Nth Fibonacci Number\n\nThe n-th term of Fibonacci series F(n), where F(n) is a function, is calculated using the following formula:\n\n    F(n) = F(n - 1) + F(n - 2),\n    Where, F(1) = 1, F(2) = 1\n\nProvided 'n' you have to find out the n-th Fibonacci Number. Handle edges cases like when 'n' = 1 or 'n' = 2 by using conditionals like if else and return what's expected.\n\n\"Indexing is start from 1\"\n\n```py\nn=int(input())\narr=[1]*(n+1)\nfor i in range(3,n+1):\n    arr[i]=arr[i-1]+arr[i-2]\nprint(arr[n])\n```\n\n### Day 3: Number of digits\n\nYou are given a number 'n'.\nReturn number of digits in ‘n’.\n\n```py\nimport math\n\ndef countDigits(n: int) -\u003e int:\n    # Write your code here\n    return math.floor(math.log10(n))+1\n```\n\n### Day 4: Prime Number\n\nA prime number is a positive integer that is divisible by exactly 2 integers, 1 and the number itself.\n\nYou are given a number 'n'.\n\nFind out whether 'n' is prime or not.\n\n```py\ndef isPrime(n:int) -\u003e bool:\n    # Write your code here\n    if n==1:\n        return False\n    root=int(n**0.5)\n    for i in range(2,root+1):\n        if n%i==0:\n            return False\n    return True\n```\n\n### Day 5: Check Sorted Array\n\nYou have been given an array ‘a’ of ‘n’ non-negative integers.You have to check whether the given array is sorted in the non-decreasing order or not.\n\nYour task is to return 1 if the given array is sorted. Else, return 0.\n\nExample :\nInput: ‘n’ = 5, ‘a’ = [1, 2, 3, 4, 5]\nOutput: 1\n\nThe given array is sorted in non-decreasing order; hence the answer will be 1.\n\n```py\ndef isSorted(n: int,  a: [int]) -\u003e int:\n    # Write your code here.\n    for i in range(1,n):\n        if a[i]\u003ca[i-1]:\n            return 0\n    return 1\n```\n\n### Day 6: Reverse a Number\n\nYou are given a number 'n'.\n\nReturn an integer that is the reverse of ‘n’.\n\nNote:\nReverse of ‘n’ means an integer where, the most significant digit of ‘n’ is the least significant digit of the number, the second most significant digit of ‘n’ is the second least significant digit of the number and so on.\n\n```py\nfrom typing import List\n\ndef reverseNumber(n: int) -\u003e int:\n    # Write your code here\n    rev=0\n    while n\u003e0:\n        rem=n%10\n        rev=rev*10+rem\n        n=n//10\n    return rev\n```\n\n### Day 7: Reverse an Array\n\nGiven an array 'arr' of size 'n'.\n\nReturn an array with all the elements placed in reverse order.\n\nNote:\nYou don’t need to print anything. Just implement the given function.\n\n```py\nfrom typing import *\n\ndef reverseArray(n: int, nums: List[int]) -\u003e List[int]:\n    # Write your code here\n    for i in range(n//2):\n        nums[i],nums[n-i-1]=nums[n-i-1],nums[i]\n    return nums\n```\n\n### Day 8: GCD or HCF\n\nYou are given two integers 'n', and 'm'.\n\nCalculate 'gcd(n,m)', without using library functions.\n\nNote:\nThe greatest common divisor (gcd) of two numbers 'n' and 'm' is the largest positive number that divides both 'n' and 'm' without leaving a remainder.\n\n```py\ndef calcGDC(n:int, m: int) -\u003e int:\n    # Write your code here\n    a=min(n,m)\n    b=max(n,m)\n    while a!=0:\n        rem=b%a\n        b=a\n        a=rem\n    return b\n```\n\n### Day 9: Second Largest Number\n\nYou have been given an array ‘a’ of ‘n’ unique non-negative integers.\n\nFind the second largest and second smallest element from the array.\n\nReturn the two elements (second largest and second smallest) as another array of size 2.\n\n```py\ndef getSecondOrderElements(n: int,  a: [int]) -\u003e [int]:\n    # Write your code here.\n    n=len(a)\n    pmax,smax=float('-inf'),float('-inf')\n    pmin,smin=float('inf'),float('inf')\n\n    for i in range(n):\n        if a[i]\u003epmax:\n            smax=pmax\n            pmax=a[i]\n        elif a[i]\u003cpmax and a[i]\u003esmax:\n            smax=a[i]\n\n        if a[i]\u003cpmin:\n            smin=pmin\n            pmin=a[i]\n        elif a[i]\u003epmin and a[i]\u003csmin:\n            smin=a[i]\n    return [smax,smin]\n```\n\n### Day 10: Highest / Lowest Frequency Elements\n\nGiven an array 'v' of 'n' numbers.\n\nYour task is to find and return the highest and lowest frequency elements.\n\nIf there are multiple elements that have the highest frequency or lowest frequency, pick the smallest element.\n\n```py\nfrom typing import List\nfrom collections import Counter\ndef getFrequencies(v: List[int]) -\u003e List[int]:\n    # Write your code here\n    freq = Counter(v)\n\n    min_val,min_freq=float('inf'),float('inf')\n    max_val,max_freq=0,0\n    for val,fq in freq.items():\n        if fq==min_freq and val\u003cmin_val:\n            min_val=val\n        if fq\u003cmin_freq:\n            min_freq,min_val=fq,val\n\n        if fq==max_freq and val\u003cmax_val:\n            max_val=val\n        if fq\u003emax_freq:\n            max_freq,max_val=fq,val\n\n\n    return [max_val,min_val]\n```\n\n### Day 11: Two Sum\n\nSam want to read exactly ‘TARGET’ number of pages.\n\nHe has an array ‘BOOK’ containing the number of pages for ‘N’ books.\n\nReturn YES/NO, if it is possible for him to read any 2 books and he can meet his ‘TARGET’ number of pages.\n\nExample:\nInput: ‘N’ = 5, ‘TARGET’ = 5\n‘BOOK’ = [4, 1, 2, 3, 1]\n\nOutput: YES\nExplanation:\nSam can buy 4 pages book and 1 page book.\n\n```py\ndef read(n: int, book: [int], target: int) -\u003e str:\n    # Write your code here.\n    seen=set()\n    for num in book:\n        if target-num in seen:\n            return \"YES\"\n        seen.add(num)\n    return \"NO\"\n```\n\n### Day 12: Add One To Number\n\nGiven a non-negative number represented as an array of digits, you have to add 1 to the number, i.e, increment the given number by one.\n\nThe digits are stored such that the most significant digit is at the starting of the array and the least significant digit is at the end of the array.\n\nFor Example\nIf the given array is {1,5,2}, the returned array should be {1,5,3}.\n\nNote:\n\nInput array can contain leading zeros, but the output array should not contain any leading zeros (even if the input array contains leading zeroes).\nFor Example:\nIf the given array is {0,2}, the returned array should be {3}.\n\n```py\ndef addOneToNumber(arr):\n    #   Write your code here\n    n=len(arr)\n    carry=1\n    for i in range(n-1,-1,-1):\n        arr[i]+=carry\n        carry=arr[i]//10\n        arr[i]%=10\n\n    if carry:\n        arr.insert(0,carry)\n\n    while arr[0]==0:\n        arr.pop(0)\n```\n\n### Day 13: Binary Search\n\nYou are given an integer array 'A' of size 'N', sorted in non-decreasing order. You are also given an integer 'target'. Your task is to write a function to search for 'target' in the array 'A'. If it exists, return its index in 0-based indexing. If 'target' is not present in the array 'A', return -1.\n\nNote:\nYou must write an algorithm whose time complexity is O(LogN)\n\n```py\ndef search(nums: [int], target: int):\n    # write your code logic !!\n    l, r = 0, len(nums) - 1\n    while l \u003c= r:\n        mid = (l + r) // 2\n        if nums[mid] == target:\n            return mid\n        elif nums[mid] \u003c target:\n            l = mid + 1\n        else:\n            r = mid - 1\n    return -1\n```\n\n### Day 14: Sort An Array of 0s, 1s and 2s\n\nYou have been given an array/list 'arr' consisting of 'n' elements.\n\nEach element in the array is either 0, 1 or 2.\n\nSort this array/list in increasing order.\n\nDo not make a new array/list. Make changes in the given array/list.\n\nExample :\nInput: 'arr' = [2, 2, 2, 2, 0, 0, 1, 0]\n\nOutput: Final 'arr' = [0, 0, 0, 1, 2, 2, 2, 2]\n\nExplanation: The array is sorted in increasing order.\n\n```py\ndef sortArray(arr, n):\n\n    # Write your code here\n    count1=0\n    for i in range(n):\n        if arr[i]!=0:\n            count1+=1\n        else:\n            arr[i],arr[i-count1]=arr[i-count1],arr[i]\n    count2=0\n    for i in range(n-count1,n):\n        if arr[i]==2:\n            count2+=1\n        else:\n            arr[i],arr[i-count2]=arr[i-count2],arr[i]\n```\n\n### Day 15: Implement Lower Bound\n\nYou are given an array 'arr' sorted in non-decreasing order and a number 'x'. You must return the index of the lower bound of 'x'.\n\nNote:\n\n1. For a sorted array 'arr', 'lower_bound' of a number 'x' is defined as the smallest index 'idx' such that the value 'arr[idx]' is not less than 'x'.If all numbers are smaller than 'x', then 'n' should be the 'lower_bound' of 'x', where 'n' is the size of array.\n\n2. Try to do this in O(log(n)).\n\nExample:\nInput: ‘arr’ = [1, 2, 2, 3] and 'x' = 0\n\nOutput: 0\n\nExplanation: Index '0' is the smallest index such that 'arr[0]' is not less than 'x'.\n\n```py\ndef lowerBound(arr: [int], n: int, x: int) -\u003e int:\n    # Write your code here\n    l=0\n    r=n-1\n    while l\u003c=r:\n        mid=(l+r)//2\n        if arr[mid]==x and (arr[mid-1]\u003cx if mid\u003e0 else True):\n            return mid\n        elif arr[mid]\u003e=x:\n            r=mid-1\n        else:\n            l=mid+1\n    return l\n```\n\n### Day 16: Valid Parentheses\n\nYou're given a string 'S' consisting of \"{\", \"}\", \"(\", \")\", \"[\" and \"]\" .\n\nReturn true if the given string 'S' is balanced, else return false.\n\nFor example:\n'S' = \"{}()\".\n\nThere is always an opening brace before a closing brace i.e. '{' before '}', '(' before ').\nSo the 'S' is Balanced.\n\n```py\ndef isValidParenthesis(s: str) -\u003e bool:\n    # Write your code here\n    stack=[]\n    for c in s:\n        if c=='(' or c=='[' or c=='{':\n            stack.append(c)\n        elif c==')':\n            if stack and stack[-1]=='(':\n                stack.pop()\n            else:\n                return False\n        elif c==']':\n            if stack and stack[-1]=='[':\n                stack.pop()\n            else:\n                return False\n        elif c=='}':\n            if stack and stack[-1]=='{':\n                stack.pop()\n            else:\n                return False\n    return not stack\n```\n\n### Day 17: Implement Upper Bound\n\nYou are given a sorted array ‘arr’ containing ‘n’ integers and an integer ‘x’.Implement the ‘upper bound’ function to find the index of the upper bound of 'x' in the array.\n\nNote:\n\n1. The upper bound in a sorted array is the index of the first value that is greater than a given value.\n2. If the greater value does not exist then the answer is 'n', Where 'n' is the size of the array.\n3. Try to write a solution that runs in log(n) time complexity.\n\nExample:\n\nInput : ‘arr’ = {2,4,6,7} and ‘x’ = 5,\n\nOutput: 2\n\nExplanation: The upper bound of 5 is 6 in the given array, which is at index 2 (0-indexed).\n\n```py\nfrom typing import List\n\ndef upperBound(arr: List[int], x: int, n: int) -\u003e int:\n    # Write your code here.\n    l,r=0,n-1\n    while l\u003c=r:\n        mid=(l+r)//2\n        if arr[mid]==x and (arr[mid+1]\u003ex if mid\u003cn-1 else True):\n            return mid+1\n        elif arr[mid]\u003ex:\n            r=mid-1\n        else:\n            l=mid+1\n    return l\n```\n\n### Day 18: Spiral Matrix\n\nYou are given a 2D matrix ‘MATRIX’ of ‘N’\\*’M’ dimension. You have to return the spiral traversal of the matrix.\n\nExample:\n\nInput:\nMATRIX = [ [1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 60] ]\nOutput:\n1 3 5 7 20 60 34 30 23 10 11 16\n\nExplanation: Starting from the element in the first row and the first column, traverse from left to right (1 3 5 7), then top to bottom (20 60), then right to left (34 30 23), then bottom to up (10) and then left to right (11 16).\n\n```py\ndef spiralMatrix(matrix : List[List[int]]) -\u003e List[int]:\n    # Write your code here.\n    i,j=0,0\n    directions=[(0,1),(1,0),(0,-1),(-1,0)]\n    directionIndex=0\n    m,n=len(matrix),len(matrix[0])\n    arr=[n,m]\n    res=[]\n    while all(arr):\n        for r in range(2):\n            for c in range(arr[r]):\n                res.append(matrix[i][j])\n                if c\u003carr[r]-1:\n                    i,j=i+directions[directionIndex][0],j+directions[directionIndex][1]\n                else:\n                    directionIndex=(directionIndex+1)%4\n                    i,j=i+directions[directionIndex][0],j+directions[directionIndex][1]\n            arr[(r+1)%2]-=1\n    return res\n```\n\n### Day 19: Zero Matrix\n\nYou are given a matrix 'MATRIX' of dimension 'N' x 'M'. Your task is to make all the elements of row 'i' and column 'j' equal to 0 if any element in the ith row or jth column of the matrix is 0.\n\nNote:\n\n1. The number of rows should be at least 1.\n\n2. The number of columns should be at least 1.\n\n```py\ndef zeroMatrix(matrix, n, m):\n    # Write your code here.\n    if n\u003c=1 or m\u003c=1:\n        return matrix\n\n    first_row_have_zero=any(matrix[0][j]==0 for j in range(m))\n    first_col_have_zero=any(matrix[i][0]==0 for i in range(n))\n\n    for i in range(1,n):\n        for j in range(1,m):\n            if matrix[i][j]==0:\n                matrix[0][j]=0\n                matrix[i][0]=0\n    for i in range(1,n):\n        for j in range(1,m):\n            if matrix[0][j]==0 or matrix[i][0]==0:\n                matrix[i][j]=0\n    if first_row_have_zero:\n        for j in range(m):\n            matrix[0][j]=0\n    if first_col_have_zero:\n        for i in range(n):\n            matrix[i][0]=0\n```\n\n### Day 20: Pascal's Triangle\n\nYou are given an integer N. Your task is to return a 2-D ArrayList containing the pascal’s triangle till the row N.\n\nA Pascal's triangle is a triangular array constructed by summing adjacent elements in preceding rows. Pascal's triangle contains the values of the binomial coefficient.\n\n```py\ndef printPascal(n:int):\n    # Write your code here.\n    # Return a list of lists.\n    res=[[1]]\n    for i in range(1,n):\n        res.append([1]+[res[i-1][j]+res[i-1][j-1] for j in range(1,i)]+[1])\n    return res\n```\n\n### Day 21: Number of Inversions\n\nThere is an integer array ‘A’ of size ‘N’.\n\nNumber of inversions in an array can be defined as the number of pairs of ‘i’, ‘j’ such that ‘i’ \u003c ‘j’ and ‘A[i]’ \u003e ‘A[j]’.\n\nYou must return the number of inversions in the array.\n\nFor example,\nInput:\nA = [5, 3, 2, 1, 4], N = 5\nOutput:\n7\nExplanation:\nThe pairs satisfying the condition for inversion are (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), and (3, 4).\nThe number of inversions in the array is 7.\n\n```py\nfrom typing import *\n\nclass Solution:\n    def mergeSort(self,arr,low,high):\n        count_inversion=0\n        if low\u003chigh:\n            mid=(low+high)//2\n            count_inversion+=self.mergeSort(arr,low,mid)\n            count_inversion+=self.mergeSort(arr,mid+1,high)\n            count_inversion+=self.merge(arr,low,mid,high)\n        return count_inversion\n    def merge(self,arr,low,mid,high):\n        count_inversion=0\n        temp=[0]*(high-low+1)\n        i=low\n        j=mid+1\n        k=0\n        while i\u003c=mid and j\u003c=high:\n            if arr[i]\u003c=arr[j]:\n                temp[k]=arr[i]\n                k+=1\n                i+=1\n            else:\n                temp[k]=arr[j]\n                k+=1\n                j+=1\n                count_inversion+=mid-i+1 #se agrega la inversion\n        while i\u003c=mid:\n            temp[k]=arr[i]\n            k+=1\n            i+=1\n        while j\u003c=high:\n            temp[k]=arr[j]\n            k+=1\n            j+=1\n        for i in range(low,high+1):\n            arr[i]=temp[i-low]\n        return count_inversion\ndef numberOfInversions(a : List[int], n : int) -\u003e int:\n    # Write your code here.\n    return Solution().mergeSort(a,0,n-1)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaldohidalgo%2Fcoding-ninja-21-day-coding-challenge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaldohidalgo%2Fcoding-ninja-21-day-coding-challenge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaldohidalgo%2Fcoding-ninja-21-day-coding-challenge/lists"}