Job search
HackerEarth Surprise Question: Explain Your Approach After the Coding Tasks
Understand the optional written explanation after attempted coding tasks, distinguish answer submission from ending the test, and practice with original examples.
A HackerEarth Surprise Question can ask you to explain your approach after you have attempted or skipped the other questions in an assessment. It is an employer-enabled feature, not a universal extra question in every test. When it appears, respond to the actual prompt using the code and reasoning you personally produced; do not replace an unfinished implementation with a description of an algorithm you did not write.
Keep question submission and final assessment completion separate. This guide reviews public HackerEarth documentation checked October 23, 2026 and demonstrates two original fictional explanations. It does not reproduce an employer’s question or report an authenticated test. LandOffer publishes this guide and provides recent job listings; it does not administer HackerEarth assessments or determine their scores.

Understand when the additional question can appear
HackerEarth’s official Surprise Question description says the employer can enable it in proctoring settings. The platform randomly generates it from questions the candidate attempted and shows it after all other questions have been attempted or skipped. The response is subjective text. HackerEarth describes the feature as a way to assess understanding of the candidate’s approach.
This timing does not mean you should skip questions to force a preferred prompt. Work through the assessment under its instructions and read the additional question when the interface presents it. The public description does not promise which attempted question will be chosen or what wording you will receive.
There is also a candidate-facing Follow-up Question page describing explanations of submitted code. That page supports the broader purpose of communicating your reasoning, but it does not establish that every employer’s follow-up uses identical timing, controls or scoring. Use the instructions and question actually shown in your session.
Separate writing, submitting and ending the test
HackerEarth’s subjective-question interface guide identifies a text field and an answer-submission button. It describes the general interface; it is not a promise that every Surprise Question has an identical layout or file-upload option. Read the available controls so you can distinguish the response field from the action that submits it.
The Surprise Question article does not specify a universal autosave interval, separate extra time allowance or permission to revise earlier code afterward. Do not assume any of those. Follow your session’s displayed timer and instructions, and use the provided answer-submission control rather than treating text visible in an editor as proof of submission.
HackerEarth’s test-ending guide distinguishes question-level Submit and testing controls from End Test. Its confirmation shows remaining time and unanswered questions; after the test has ended, access is unavailable even if time remained. Check that summary before confirming the final action. The public guide does not give a Surprise Question-specific restoration process.
A useful sequence is: complete the permitted question actions, read any additional prompt, write and check the explanation, submit that answer using the displayed control, then review the final test summary. This is a reading-and-verification sequence, not a claim that we clicked those controls in a candidate account.
Explain the implementation that actually exists
Start by naming the approach used in your submitted code. Identify the input you process, the state you maintain and how you produce the requested result. Refer to meaningful variables or operations when that helps connect the prose to the implementation, without copying the entire program into the answer.
Then explain why that approach works. “I used a loop” describes syntax; “the counter equals the length of the current qualifying suffix after each item” gives the reader a reason to trust the update. Choose the explanation the prompt requests rather than listing every algorithm you know.
Finish with the relevant limits. Time and space complexity should describe this implementation, including sorting, auxiliary collections or nested work. If a known edge case fails, acknowledge the actual gap. Do not claim a fix was submitted because you can now describe how to make it.
You can practice this structure outside an assessment with self-authored exercises. During a real test, follow its rules for external resources, notes, AI tools and assistance. The examples below teach explanation before a test; they are not text to paste into an active employer assessment or a substitute for understanding your own solution.
An explanation can be concise without omitting the decisive detail. If the prompt asks about a data structure, explain the operation it makes possible and the cost it introduces. If it asks about a failure, identify the assumption and its consequence rather than repeating the full solution. Keep a hypothetical improvement visibly separate from the implemented approach: “I would add a guard” does not mean “my submitted code has a guard.”
Worked explanation one: a single-pass run counter
This is an original fictional exercise. Given integer readings and a threshold, return the longest consecutive run of readings at least that threshold. The invented implementation maintains current and best, both initially zero. For each reading, it increments current if the reading qualifies, otherwise resets it to zero, then updates best with the larger value.
Here is the completed three-part explanation for that implementation:
Claim. “My code scans the readings once and tracks two lengths. current measures the qualifying run ending at the latest reading, while best records the longest run encountered anywhere so far. I return best, including zero when the input contains no qualifying readings.”
Reasoning. “A reading below the threshold breaks every run ending at that position, so resetting current is necessary. A qualifying reading extends the immediately preceding qualifying run by one. Updating best after every reading retains a run even when a later value breaks it. This scans n readings in O(n) time and uses O(1) auxiliary space.”
Boundary tests. “For readings [4, 7, 8, 2, 9] and threshold 7, the successive current values are 0, 1, 2, 0, 1, so the result is 2. [7, 7] returns 2 because equality qualifies. An empty list returns 0; [1, 2] at threshold 7 also returns 0. These checks describe the invented code, not hidden assessment results.”
The answer connects the state update to the result instead of merely announcing “linear time.” It also avoids an incorrect explanation based on sorting: sorting would destroy the original adjacency that defines a consecutive run. If the actual submitted code sorted first, this otherwise polished paragraph would misrepresent it.
A small trace makes the reasoning inspectable. After reading 8, current and best are both 2. Reading 2 changes current to zero but leaves best at 2. Reading 9 then starts a new run of length one. The final maximum therefore belongs to the earlier run, not necessarily the last segment of the input.
Worked explanation two: first appearances with a stated limitation
A second original exercise asks for distinct ticket labels in first-appearance order. The fictional code creates an empty set seen and list result. It scans the labels, appending a label and adding it to seen only if the exact label has not been seen. Labels in this exercise are case-sensitive strings; no normalization is specified.
Claim. “My implementation preserves the order in which distinct exact strings first appear. It uses the set for membership checks and the list for ordered output. It does not sort the labels, and it treats different capitalization as different strings.”
Reasoning. “After each processed label, seen contains the labels in the processed prefix and result contains their first appearances in input order. A repeated label leaves both collections unchanged; a new label is appended at its first occurrence. Expected membership lookup makes the scan expected O(n) in the number of labels when per-label operations are treated as constant cost. The collections use O(k) entries for k distinct labels.”
Boundary tests. “For [amber, blue, amber, Amber], the output is [amber, blue, Amber]. [blue, blue] produces [blue], and an empty input produces an empty list. If the requirement instead treats amber and Amber as equal, my current code does not implement that requirement. I would need to clarify the required normalization and change the code; I have not done so in this version.”

This explanation keeps the case-sensitive behavior visible. The limitation follows from the described membership key. It also keeps the complexity honest: string processing has costs of its own, so the answer states the simplified unit-cost assumption rather than presenting expected set lookup as a universal worst-case guarantee.
Both examples were checked locally against their stated inputs using self-authored Python functions. Those checks verify the article’s teaching examples only. They do not show that the functions were submitted to HackerEarth, passed an employer’s tests or met an assessment’s input format.
Distinguish a test you ran from a result you inferred
The official testing guide explains that custom input must follow the problem’s input format. It also says a custom-input run does not run the sample and internal test cases. Consequently, “my custom case returned the expected value” is narrower than “my solution passed every test.”
When explaining your work, name the checks you actually performed and their observed output if the prompt asks. Keep an untested boundary as a reasoning claim, not an observed pass. A boundary case you think of afterward remains unexecuted unless you actually run it through the permitted test controls.
For a partially completed solution, describe the working portion and the remaining issue clearly. If your code handles the general case but mishandles an empty input, say where that assumption appears. Avoid saying the assessment accepted your explanation unless the interface or employer has actually supplied that result.
The explanation should also match the submitted version. If you tested an earlier version and then changed a condition, its earlier result may no longer establish the final behavior. Identify the version you are discussing and avoid borrowing correctness from an implementation you abandoned.
Use a final consistency check before the ending confirmation
Read the displayed prompt one more time. Does it ask why you chose the approach, how the algorithm works, how you tested it or what you would improve? Answer the requested question directly. A long overview can still miss a short question about one decision.
Check three relationships: the claim matches the code, the reasoning supports that claim, and the test description matches what was actually observed. In the first fictional example, “at least” must agree with the equality check. In the second, the exact-string membership rule must agree with the case-sensitive output. These are concrete consistency checks, not a predicted grading rubric.
Do not infer a required word count from the length of these examples. They are expanded teaching demonstrations with traces and limitations. A live prompt may call for a narrower answer, and the response field may display its own constraints. Read those constraints before spending the remaining time on extra background that the question did not request.
Finally, distinguish a drafted response, an answer submitted through its control and an assessment ended through confirmation. If something fails, follow the session’s official support route and accurately describe the visible issue. Do not invent a retry entitlement or assume ending the test will preserve an unsent explanation.
After the assessment, keep a private record of permitted completion information without sharing confidential prompts or code. When planning additional applications, browse recent roles on LandOffer.ai. Before another test, practice a claim, a reason and a boundary check for one solution you wrote yourself.
Sources and Further Reading
- HackerEarth: Surprise Question — employer setting, trigger and text-response description; checked October 23, 2026.
- HackerEarth: Follow-up Question — purpose of explaining submitted code.
- HackerEarth: Subjective question interface — general text-response controls, not a session-specific guarantee.
- HackerEarth: Ending your test — question submission versus final test confirmation.
- HackerEarth: Testing your code — scope of custom-input runs.


