PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's competency in implementing binary search and handling integer arithmetic and overflow considerations when checking numeric properties. Commonly asked to assess algorithmic complexity analysis and practical coding ability within the Coding & Algorithms domain, it emphasizes practical application and O(log n) performance rather than purely conceptual reasoning.

  • medium
  • LinkedIn
  • Coding & Algorithms
  • Software Engineer

Check perfect square using binary search

Company: LinkedIn

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Perfect Square Check (Binary Search) Given a positive integer `n`, determine whether it is a **perfect square** (i.e., there exists an integer `x` such that `x*x = n`). ### Requirements - Do **not** use built-in square-root functions. - Implement an `O(log n)` approach. ### Input - Integer `n` (`1 <= n <= 2^31 - 1`). ### Output - Return `true` if `n` is a perfect square, otherwise `false`. ### Examples - `n = 16` -> `true` (4×4) - `n = 14` -> `false` ### Notes - Be careful about integer overflow when computing `mid * mid`.

Quick Answer: This question evaluates a candidate's competency in implementing binary search and handling integer arithmetic and overflow considerations when checking numeric properties. Commonly asked to assess algorithmic complexity analysis and practical coding ability within the Coding & Algorithms domain, it emphasizes practical application and O(log n) performance rather than purely conceptual reasoning.

Return whether n is a perfect square using binary search without sqrt.

Constraints

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

Examples

Input: (16,)

Expected Output: True

Explanation: Perfect square.

Input: (14,)

Expected Output: False

Explanation: Not a square.

Input: (1,)

Expected Output: True

Explanation: Smallest positive square.

Input: (2147395600,)

Expected Output: True

Explanation: Large square near 32-bit limit.

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
  • AI Coding 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)
  • Can You Place N Objects? - LinkedIn (medium)