HARDasked at 1 company

Find a Value of a Mysterious Function Closest to Target

A hard-tier problem at 46% community acceptance, tagged with Array, Binary Search, Bit Manipulation. Reported in interviews at American Express and 0 others.

Founder's read

American Express asked this problem once, and it sits at 46% acceptance rate with a hard difficulty tag. You're dealing with a function nobody hands you the definition for, a mystery that unfolds through the data itself. The actual work is reverse-engineering the pattern from an array, then hunting for the value closest to a target you can't brute-force in time. If you blank on the binary search angle or the bit manipulation trick during your live OA, StealthCoder reads the problem and surfaces the solution in seconds, invisible to the proctor.

Companies asking
1
Difficulty
HARD
Acceptance
46%

Companies that ask "Find a Value of a Mysterious Function Closest to Target"

If this hits your live OA

Find a Value of a Mysterious Function Closest to Target is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.

Get StealthCoder
What this means

The core trap is treating this like a simple search. The function isn't directly callable, so you can't just query every possible output. You need to extract or build the function's behavior from the array using bit manipulation or pattern recognition, then binary search over the output space to find the closest match to your target. The segment tree topic hints at range queries, but most candidates miss that the real bottleneck is understanding what the function computes in the first place. Once you map the actual values the function can produce, binary search on that sorted set to minimize distance to target. Common failure: trying to brute-force all possibilities without first narrowing the search space. StealthCoder hedges the moment you realize you don't know the pattern and the clock is ticking.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Find a Value of a Mysterious Function Closest to Target recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find a Value of a Mysterious Function Closest to Target interview FAQ

Is this problem still asked at top companies?+

American Express has confirmed asking it. It's a hard problem with moderate acceptance (46%), so it's not a filter question. Expect it if you're interviewing there or at a company with similar low-level systems or financial risk modeling.

What's the trick to figuring out the mystery function?+

You can't guess it. Use bit manipulation to test properties of the array elements and function outputs. Look for bitwise patterns, XOR relationships, or cumulative bit behavior. The function definition emerges from the data itself, not from the problem statement.

Why is binary search relevant here?+

Once you know what outputs the function can produce, binary search lets you find the closest value to target in log time. Without it, you're checking thousands of candidates. The sorted output space is your playground, not the input array.

Does segment tree actually help solve this?+

Segment tree is listed as a topic but may be a red herring or used for a secondary optimization. Focus first on understanding the function and binary search. A segment tree could accelerate range min/max queries if the function is range-based, but it's not the main path.

How much time should I spend reverse-engineering the function?+

If you can't see the pattern in 5 to 10 minutes, you're probably overthinking it. Start writing test cases, check small array values against target outputs, and look for bitwise or cumulative patterns. Move to binary search once you've validated your hypothesis.

Want the actual problem statement? View "Find a Value of a Mysterious Function Closest to Target" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.