Skip to main content
All Questions

A C++ function meant to detect taxicab numbers (sums of two positive cubes in exactly two ways) counts matches with two nested loops and returns count == 2. Find and fix the bug.

Unlock detailed company stats for this questionUpgrade
A C++ function should return true when x is a taxicab number, a positive integer that is a sum of two positive cubes in exactly two distinct ways (1729 = 1^3 + 12^3 = 9^3 + 10^3). It counts matches with two nested loops over i and j that both start at 1 and stop when the cube reaches x, and returns count == 2. Find the bug and fix it with minimal changes.

Community answers

No answers contributed by the community yet.

Related courses

Course

Behavioral Interviews: A Practical Guide for Engineers

Get offers at the level you deserve. Prep for senior+ behavioral interviews at FAANG and Tier-1 companies. Made with staff and principal engineers from Meta, Netflix, Google, and more. Avoid downleveling, elevate past projects, and stop sounding like a robot.

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.