PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency with double-ended queue semantics, fixed-capacity data structure design, constant-time (O(1)) operations, and correct handling of boundary conditions and wraparound.

  • medium
  • Applied
  • Coding & Algorithms
  • Machine Learning Engineer

Implement a Fixed-Capacity Deque

Company: Applied

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Design and implement a fixed-capacity double-ended queue. The data structure is initialized with an integer capacity `k` and must support the following operations in `O(1)` time: - `insertFront(value)`: Insert `value` at the front. Return `true` if successful, or `false` if the deque is full. - `insertLast(value)`: Insert `value` at the back. Return `true` if successful, or `false` if the deque is full. - `deleteFront()`: Delete the front element. Return `true` if successful, or `false` if the deque is empty. - `deleteLast()`: Delete the back element. Return `true` if successful, or `false` if the deque is empty. - `getFront()`: Return the front element, or `-1` if the deque is empty. - `getRear()`: Return the back element, or `-1` if the deque is empty. - `isEmpty()`: Return whether the deque is empty. - `isFull()`: Return whether the deque is full. You may assume `1 <= k <= 1000` and values are integers. Explain your representation and handle wraparound correctly.

Quick Answer: This question evaluates proficiency with double-ended queue semantics, fixed-capacity data structure design, constant-time (O(1)) operations, and correct handling of boundary conditions and wraparound.

Simulate a circular double-ended queue with O(1) operations and return one output per operation.

Constraints

  • Inputs are provided as Python literals matching the function signature.
  • Return a deterministic exact-match result.

Examples

Input: (3, [['insertLast',1], ['insertLast',2], ['insertFront',3], ['insertFront',4], ['getRear'], ['isFull'], ['deleteLast'], ['insertFront',4], ['getFront']])

Expected Output: [True, True, True, False, 2, True, True, True, 4]

Explanation: Wraparound and full insert.

Input: (1, [['isEmpty'], ['deleteFront'], ['insertFront',9], ['getRear']])

Expected Output: [True, False, True, 9]

Explanation: Empty and singleton.

Hints

  1. Choose a representation that makes the core operation simple.
  2. Handle empty and boundary inputs before the main algorithm.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Multi-Agent Collision Simulator (Unicycle Kinematics) - Applied (medium)
  • Merge Overlapping Collinear Segments - Applied (hard)
  • Implement Nested Transactional Key-Value Store - Applied (hard)
  • Merge overlapping 2D line segments - Applied (medium)
  • Group duplicate files by content - Applied (easy)