Code Logo

Queue Is Empty

Published at25 Jul 2026
Basic Queue Easy 0 views
Like0

Check if a queue (represented as an array) is empty. Return true if the array has no elements, false otherwise.

Example Input & Output

Example 1
Input
[0]
Output
false
Explanation

Zero is still an element

Example 2
Input
[]
Output
true
Explanation

Empty again

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

Has elements

Example 4
Input
[1]
Output
false
Explanation

Has one element

Example 5
Input
[]
Output
true
Explanation

Empty queue

Algorithm Flow

Recommendation Algorithm Flow for Queue Is Empty
Recommendation Algorithm Flow for Queue Is Empty

Solution Approach

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

Best Answers

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