Algorithms and Data Structures

  • Profound Academy

    • Status
      • 1
        Implementation
      • 2
        Bitwise operations
      • 3
        Prefix Sums
      • 4
        Sliding window / Two pointers
      • 5
        Modular Arithmetic
      • 6
        Number Theory
      • 7
        Binary Search
      • 8
        Basic Sorting
      • 9
        Greedy Algorithms
      • 10
        Basic Dynamic Programming
      • 11
        Recursion
      • 12
        Linked LIst
      • 13
        Queue & Stack
      • 14
        Binary tree + BST
      • 15
        Divide & Conquer + Advanced Sorting
      • 16
        Heap
      • 17
        Hashing
      • 18
        Graph Representation
      • 19
        BFS

  • Merge two sorted arrays

    Given two sorted arrays and of lengths n and m, you are asked to obtain a new array by combining those two that would be sorted as well.

    Input

    The first line of the input contains two integers n and m (1 ≤ n, m ≤ ).
    The second line contains n space-separated sorted integers ().
    The last line contains m space-separated sorted integers ().

    Output

    The program should print n+m space-separated integers in increasing order representing the combination of a and b.

    Examples

    Input
    Output
    3 5 -2 4 8 -3 -1 0 1 1
    -3 -2 -1 0 1 1 4 8
     

    Constraints

    Time limit: 2.5 seconds

    Memory limit: 512 MB

    Output limit: 25 MB

    To check your solution you need to sign in
    Sign in to continue