Code Logo

Queue Size

Published at25 Jul 2026
Basic Queue Easy 0 views
Like0

Return the number of elements in a queue (array). This is the size/length of the array.

Example Input & Output

Example 1
Input
[1,2,3]
Output
3
Explanation

Three elements

Example 2
Input
[]
Output
0
Explanation

Empty

Example 3
Input
[5]
Output
1
Explanation

Single

Example 4
Input
[0]
Output
1
Explanation

Zero is still an element

Example 5
Input
[10,20,30,40,50]
Output
5
Explanation

Five elements

Algorithm Flow

Recommendation Algorithm Flow for Queue Size
Recommendation Algorithm Flow for Queue Size

Solution Approach

function solution(arr) {
  return arr.length;
}

Best Answers

java
class Solution {
    public int solution(int[] nums) {
        return nums.length;
    }
}