Amazon Coding Interview Question | Leetcode 622 | Design Circular Queue

preview_player
Показать описание
In this video, we introduce how to solve the "Design Circular Queue" question which is used by big tech companies like Google, Facebook, Amazon in coding interviews. We also cover how to behave during a coding interview, e.g. communication, testing, coding style, etc.

Please subscribe to this channel if you like this video. I will keep updating this channel with videos covering different topics in interviews from big tech companies.

Рекомендации по теме
Комментарии
Автор

My Python implementation:

class MyCircularQueue(object):

def __init__(self, k):
"""
:type k: int
"""
self.size = 0
self.k = k
self.arr = [None] * k
self.tail = -1
self.head = 0

def enQueue(self, value):
"""
:type value: int
:rtype: bool
"""
if self.size >= self.k:
return False

self.tail = (self.tail + 1) % self.k
if not self.arr[self.tail]:
self.arr[self.tail] = value
self.size += 1
return True

def deQueue(self):
"""
:rtype: bool
"""
if self.isEmpty():
return False
self.arr[self.head] = None
self.head = (self.head + 1) % self.k
self.size -= 1
return True

def Front(self):
"""
:rtype: int
"""
if self.isEmpty():
return -1
return self.arr[self.head]

def Rear(self):
"""
:rtype: int
"""
if self.isEmpty():
return -1
return self.arr[self.tail]

def isEmpty(self):
"""
:rtype: bool
"""
return self.size == 0


def isFull(self):
"""
:rtype: bool
"""
return self.size == self.k

edwardteach
welcome to shbcf.ru