← LinkedIn Interview Insights

LinkedIn·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

LinkedIn coding screen, one algorithm question the whole time. Pretty standard binary search territory but the no-sqrt constraint trips you up if you haven't seen it before.

Questions Asked (1)

Q1

Given a non-negative integer n, determine whether it is a perfect square without using any built-in square root function. Your solution should run in O(log n) time.

Algorithms & Data Structures
Author's notes

My first instinct was to just iterate from 1 upward and check k*k == n, which works but is obviously O(sqrt n).

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use binary search to find the integer square root of n in the range [0, n]. At each step, compute mid*mid and compare with n, adjusting the search range accordingly. If an exact match is found, n is a perfect square; otherwise, it is not.

Pro tip: Mention that binary search is optimal for O(log n) and that using integer arithmetic avoids floating-point precision issues. Also, handle edge cases like n=0 and n=1 explicitly.

1. Clarify constraints and edge cases

Confirm that n is non-negative and discuss edge cases such as n=0 and n=1, which are perfect squares. Also, consider the maximum value of n to ensure integer overflow is handled (e.g., use long in Java).

2. Choose binary search approach

Explain that binary search on the range [0, n] yields O(log n) time. Alternatively, use Newton's method for integer square root, but binary search is simpler and meets the requirement.

3. Implement binary search

Initialize low=0, high=n. While low <= high, compute mid = low + (high - low)/2. Compute square = mid*mid (using long to avoid overflow). If square == n, return true. If square < n, set low = mid + 1; else set high = mid - 1.

4. Return result and analyze complexity

If the loop ends without finding an exact square, return false. State that time complexity is O(log n) and space complexity is O(1).

Key Points to Mention

  • Binary search on the answer space [0, n]
  • Avoiding integer overflow by using long or checking mid <= n/mid
  • Time complexity O(log n) and space complexity O(1)
  • Handling edge cases: n=0, n=1, and large n
  • Alternative approaches like Newton's method (optional)
  • Why built-in sqrt is disallowed and how integer arithmetic ensures precision

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.