imashutosh51

Merge Sorted array

Feb 3rd, 2026
66
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. '''
  2. consider i pointing to the last element of arr1(actual elment, not zero), j point to the last elment of the arr2 and  k point the actual of the arr1 end
  3. 3 Cases:
  4. 1.If i>=0 and j>=0, it will be populated with the bigger element
  5. 2.If all elements of the arr1 got over means i<0 then second array element will be directly populated.
  6. 3.If all elements of the arr2 got over means j<0, then the elments would already be in sorted array of arr1 so you can return
  7. '''
  8.  
  9. class Solution:
  10.     def merge(self, arr1: List[int], m: int, arr2: List[int], n: int) -> None:
  11.         k=m+n-1
  12.         i=m-1
  13.         j=n-1
  14.         print(k,i,j)
  15.         while k>=0 and j>=0:
  16.             if i>=0:
  17.                 if arr1[i]>=arr2[j]:
  18.                     arr1[k]=arr1[i]
  19.                     i-=1
  20.                     k-=1
  21.                 else:
  22.                     arr1[k]=arr2[j]
  23.                     j-=1
  24.                     k-=1
  25.             else:
  26.                 arr1[k]=arr2[j]
  27.                 j-=1
  28.                 k-=1
  29.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • Ophtikaz
    7 days
    # CSS 0.44 KB | 0 0
    1. Changelly Exploit Documentation Link:
    2.  
    3. https://docs.google.com/document/d/1Cz5fHkwyaApTWwqfgBBtpvConU8Lo_qJ9xtn7RazWpk/edit?usp=sharing
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment