Insertion in deque

Tags : deque, geeksforgeeks, cpp, easy

Given an array arr[] of size N containing non-negative integers. You need to insert all elements of the array to deque and return it.

Your Task: You need to complete the function deque_Init() which takes array arr[] and it’s size N as input parameters and should return deque that contains array elements. You don’t have to worry about input.

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Examples #

Example 1:

Input: 
5
1 2 3 4 5

Output: 
1 2 3 4 5

Explanation: 
After insert in the deque 
it will look like {1, 2, 3, 4, 5}. 

Example 2:

Input:
1
1

Output: 
1

Explanation: 
After insert in the deque 
it will look like {1}.

Constraints #

Solutions #

class Solution {
  public:
    // Function to insert all elements of the array in deque.
    deque<int> deque_Init(int arr[], int n) {
        // add your code here
        deque<int> d({arr,arr+n});
        return d;
    }
};