PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates array traversal, adjacency-constraint reasoning, and greedy placement intuition, emphasizing handling of boundary conditions and counting feasible placements.

  • medium
  • LinkedIn
  • Coding & Algorithms
  • Software Engineer

Can You Place N Objects?

Company: LinkedIn

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a binary array `slots` representing a row of locations. `1` means the location is already occupied, and `0` means it is empty. You want to place `n` new objects into the row. A new object can be placed at index `i` only if: - `slots[i] == 0` - the left neighbor is either out of bounds or equal to `0` - the right neighbor is either out of bounds or equal to `0` Determine whether it is possible to place at least `n` new objects without moving any existing ones. Example: - For `slots = [1, 0, 0, 0, 0, 1]`, the maximum number of new objects that can be placed is `1`. - Therefore, the answer is `true` when `n = 1`, and `false` when `n = 2`. Return a boolean value.

Quick Answer: This question evaluates array traversal, adjacency-constraint reasoning, and greedy placement intuition, emphasizing handling of boundary conditions and counting feasible placements.

You are given a binary array `slots` representing a row of locations. A value of `1` means the location is already occupied, and `0` means it is empty. You want to place `n` new objects into the row. A new object can be placed at index `i` only if: - `slots[i] == 0` - the left neighbor is either out of bounds or equal to `0` - the right neighbor is either out of bounds or equal to `0` Determine whether it is possible to place at least `n` new objects without moving any existing ones. For example, for `slots = [1, 0, 0, 0, 0, 1]`, the maximum number of new objects that can be placed is `1`, so the answer is `True` when `n = 1` and `False` when `n = 2`.

Constraints

  • 0 <= len(slots) <= 20000
  • Each element of `slots` is either 0 or 1
  • 0 <= n <= len(slots)

Examples

Input: ([1, 0, 0, 0, 0, 1], 1)

Expected Output: True

Explanation: You can place one new object at index 2. That satisfies the requirement of placing at least 1 object.

Input: ([1, 0, 0, 0, 0, 1], 2)

Expected Output: False

Explanation: Only one valid placement is possible in this row, so placing 2 objects is impossible.

Input: ([0], 1)

Expected Output: True

Explanation: The only slot is empty and has no neighbors, so one object can be placed there.

Input: ([], 0)

Expected Output: True

Explanation: Placing zero objects is always possible, even when the row is empty.

Input: ([0, 0, 0, 0, 0], 3)

Expected Output: True

Explanation: You can place objects at indices 0, 2, and 4 for a total of 3.

Input: ([0, 1, 0], 1)

Expected Output: False

Explanation: Neither empty slot can be used because each is adjacent to an occupied slot.

Hints

  1. Try scanning from left to right and greedily placing an object whenever the current position is valid.
  2. Be careful with the first and last positions since one neighbor may be out of bounds.
Last updated: Apr 19, 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

  • Count Trips From Vehicle Logs - LinkedIn (easy)
  • Design O(1) Randomized Multiset - LinkedIn (easy)
  • Process Mutable Matrix Sum Queries - LinkedIn (medium)
  • Design a Randomized Multiset - LinkedIn (medium)
  • Debug Queues and Solve Arrays - LinkedIn (easy)