Reported December 2024
Quoramath

Count Powers Of K

Reported by candidates from Quora's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Quora OA. Under 2s to a working solution.
Founder's read

Quora's December OA included a problem asking you to count powers of K. You're staring at it and wondering if it's a math trick or a search problem. The core idea is simple: given a number, figure out how many times you can divide it by K before you can't anymore, or count how many powers of K fit into a range. StealthCoder sits quietly in the background during your live assessment, ready to catch the pattern if you blank on the formula.

Pattern and pitfall

This is a math and counting problem disguised as iteration. The naive approach is a loop: keep dividing by K until the remainder isn't zero, counting each step. The trick is recognizing that you're really asking 'how many times does K divide evenly into N,' which is logarithm territory. If the problem asks for a range, you're doing prefix counts: count powers up to the upper bound, subtract count up to the lower bound. Common pitfall: forgetting that K to the power of zero is 1, so you need to handle that edge case. StealthCoder lets you verify the exact input constraints and output format in real time if you get stuck on whether to include 1 or exclude it.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Count Powers Of K cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Quora's OA.

Quora reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Powers Of K FAQ

Is this just repeated division?+

Yes, fundamentally. You divide by K and count until you hit a remainder or reach 1. For large numbers, you could use logarithms instead, but the loop is clearer and works fine within typical constraints.

What if K is 1?+

K=1 breaks everything because 1 raised to any power is 1. Most problems exclude it or state K > 1 upfront. Check the constraints carefully on the live OA.

Do I include 1 in the count?+

Depends on the problem statement. K to the power of zero equals 1. If the problem asks 'count how many powers of K exist,' clarify whether that means powers 1, K, K^2,... or includes K^0. The problem text on the OA will make it explicit.

What's the time complexity?+

O(log K of N) for a single count, since you're dividing by K each time. If you're handling a range or multiple queries, you might precompute or use a formula. Stay efficient but don't over-engineer.

How do I prepare for this in 48 hours?+

Write out the loop by hand on paper. Test K=2, N=8 (should give 3: powers 1, 2, 4). Trace through an off-by-one case. Know your edge cases. That's it.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Quora.

OA at Quora?
Invisible during screen share
Get it