Test Execution Success Rate
Reported by candidates from Lenskart's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Lenskart's Test Execution Success Rate showed up in reports from September 2026, and it's a SQL question that looks trivial until the edge cases hit. Up to 10^5 rows means you can't loop or process anything row by row, so one aggregate query has to do all the work. You count valid results, count the true ones, divide, and round. The traps are case variants, whitespace-only strings, and the zero-valid case. If you blank on the exact syntax during the OA, StealthCoder runs invisibly as a safety net while you finish.
The problem
The table test_results stores test-result strings. Compare values case-insensitively. true is a successful valid result. false is an unsuccessful valid result. null and strings containing only whitespace are ignored. Return one column, success_rate, equal to 100 * true_count / valid_count, rounded to two decimal places. If valid_count is 0, return 0.00. An exact halfway value rounds up. Input table test_resultsColumnMeaning result_positionOne-based input position result_valueCase-insensitive test-result string Tables test_results: result_position PK (Integer), result_value (Text) Constraints The test_results table has between 1 and 10^5 rows. result_position is unique and non-null. result_value is non-null and is a case variant of true, false, or null, or it contains only whitespace.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is conditional aggregation in a single pass. Normalize with LOWER(TRIM(result_value)). Valid rows are those where the normalized value is 'true' or 'false'. Everything else, meaning 'null' strings and whitespace-only values, gets ignored. Compute SUM(CASE WHEN normalized = 'true' THEN 1 ELSE 0 END) as true_count and SUM(CASE WHEN normalized IN ('true','false') THEN 1 ELSE 0 END) as valid_count. Then wrap the division in a CASE so valid_count = 0 returns 0.00. The pitfall is rounding. Integer division silently truncates, so multiply by 100.0 first. Also, the spec says halfway rounds up, and some engines use banker's rounding on floats, so a DECIMAL or NUMERIC cast is safer. The word 'null' is a string here, not SQL NULL. If the syntax slips under pressure, StealthCoder is the hedge for the live OA, reading the problem and handing you the query.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Test Execution Success Rate 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Lenskart's OA.
Lenskart reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Test Execution Success Rate FAQ
How hard is the Lenskart Test Execution Success Rate question really?+
Easy on logic, tricky on details. It's one table and one aggregate query. The points get lost on case handling, whitespace-only strings, the zero-valid fallback, and the halfway rounding rule. If you cover those four, you're done.
What's the trick to solving it in one query?+
Use conditional aggregation. Normalize the string with LOWER(TRIM(...)), then use SUM(CASE WHEN...) to count true rows and valid rows (true or false) in the same pass. Divide, multiply by 100, and round. No joins or subqueries are needed.
How do I handle the zero valid results case?+
Wrap the division in a CASE. If valid_count is 0, return 0.00, otherwise compute 100.0 * true_count / valid_count. Don't rely on dividing by NULLIF alone unless you also COALESCE to 0.00, since the output must be exactly that value.
Why does rounding matter here?+
The spec says an exact halfway value rounds up. Float arithmetic can land slightly off or use banker's rounding in some engines. Cast to a DECIMAL or NUMERIC type before ROUND so 12.345 style values behave as the problem expects.
How do I prepare for this in 48 hours?+
Practice conditional aggregation with CASE inside SUM and COUNT, plus TRIM, LOWER, and ROUND syntax in your SQL dialect. Write this exact query twice from memory, then test it on rows with mixed case, spaces, and an all-invalid table.