PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/LinkedIn

Check perfect square using binary search

Last updated: Mar 29, 2026

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.

Related Interview 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)
LinkedIn logo
LinkedIn
Feb 11, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
8
0

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 .

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More LinkedIn•More Software Engineer•LinkedIn Software Engineer•LinkedIn Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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.