PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in bit-level reasoning and integer arithmetic, specifically understanding binary representations and the properties that define powers of two.

  • hard
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Check whether an integer is a power of two

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

Given a signed 32-bit integer `n`, return `true` if `n` is an exact power of 2, otherwise return `false`. A power of 2 is a number of the form `2^k` where `k >= 0` (e.g., 1, 2, 4, 8, 16, ...). ## Input - `n`: an integer in the range `[-2^31, 2^31 - 1]` ## Output - Boolean indicating whether `n` is a power of 2. ## Examples - `n = 1` → `true` (2^0) - `n = 16` → `true` (2^4) - `n = 3` → `false` - `n = 0` → `false` - `n = -8` → `false` ## Follow-up - Aim for an `O(1)` / bit-manipulation solution (no loops over bits, and no precomputed set/table of powers).

Quick Answer: This question evaluates proficiency in bit-level reasoning and integer arithmetic, specifically understanding binary representations and the properties that define powers of two.

Return whether n is a positive power of two using bit manipulation.

Constraints

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

Examples

Input: (1,)

Expected Output: True

Explanation: 1 is 2^0.

Input: (16,)

Expected Output: True

Explanation: 16 is a power of two.

Input: (3,)

Expected Output: False

Explanation: 3 has multiple set bits.

Input: (0,)

Expected Output: False

Explanation: Zero is not positive.

Input: (-8,)

Expected Output: False

Explanation: Negative numbers are not powers of two.

Hints

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.
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

  • Determine Whether Courses Can Be Completed - Snapchat (medium)
  • Solve Decimal Coin Change - Snapchat (medium)
  • Find Maximum Island Perimeter - Snapchat (medium)
  • Solve Three Algorithmic Tasks - Snapchat (hard)
  • Implement a Timestamped Counter - Snapchat (medium)