Skip to content

Latest commit

 

History

History
24 lines (21 loc) · 386 Bytes

QueueRange.md

File metadata and controls

24 lines (21 loc) · 386 Bytes

Queue Range Solution

Javascript

function range(q) {
  if (q.isEmpty()) {
    return null;
  }
  let front = q.peek();
  let min = front;
  let max = front;
  while (!q.isEmpty()) {
    let currentValue = q.dequeue();
    if (currentValue < min) {
      min = currentValue;
    } else if (currentValue > max) {
      max = currentValue;
    }
  }

  return max - min;
}