Code Logo

Queue Push Back

Published at25 Jul 2026
Easy 0 views
Like0

Given an array representing a queue and a value, add the value to the back (end) of the queue.

Example Input & Output

Example 1
Input
[1,2,3],4
Output
[1,2,3,4]
Example 2
Input
[10,20],30
Output
[10,20,30]
Example 3
Input
[1],2
Output
[1,2]
Example 4
Input
[],5
Output
[5]
Example 5
Input
([],[],[1,2,3])
Output
[1,2,3]

Algorithm Flow

Recommendation Algorithm Flow for Queue Push Back
Recommendation Algorithm Flow for Queue Push Back

Solution Approach

function solution(arr, val) {
  arr.push(val);
  return arr;
}

Best Answers

java
import java.util.*;
class Solution {
    public int[] solution(int[] nums, int val) {
        int[] r=Arrays.copyOf(nums,nums.length+1);
        r[r.length-1]=val;
        return r;
    }
}