AceStack AI

Coding (Algo)

Hash maps and frequency: use counts to pair values without double-counting

Hash maps and frequency: Given nums and target, count index pairs (i, j) where i < j and nums[i] + nums[j] equals target. Equal values at different indexes count as different pairs.

Input: A JSON object { "nums": number[], "target": number }.

Output: A JSON integer equal to the number of valid index pairs.

Constraints:

  • 0 <= nums.length <= 100000
  • nums may contain duplicates and negative values
  • Do not reuse the same index in a pair

Read one JSON value from stdin and print exactly one JSON-serialized answer to stdout with no extra text.

Difficulty: MEDIUM. Variant: 8. Expect follow-up questions about complexity, edge cases, and alternative approaches.

Practice context

This coding (algo) exercise trains prompt interpretation, explicit assumptions, a concrete response, and a concise explanation of the decisions made. It is marked medium difficulty.

The signed-in workspace pro

What this task practices

This coding (algo) exercise trains the same sequence expected in an interview: understand the prompt, make assumptions explicit, produce a concrete answer, and explain the decisions behind it. The task is marked medium difficulty. The private workspace adds the tools required by this round, such as recording, code execution, diagrams, evidence panels, or structured notes. It also preserves the attempt so later feedback can be compared with previous work. Evaluation is based on task-specific criteria and the candidate seniority selected in the preparation path. Public pages never expose the reference solution, hidden tests, evaluator instructions, or another candidate’s work.

Sign in to startThe workspace and evaluation open after sign in.
Sign in to continuethis interview task

Continue to AceStack.

Continue securely with an available identity provider. If you are new, we will create your account automatically.

Continue with Google

By continuing, you agree to the Terms and acknowledge the Privacy Policy.

Your destination is saved. After access, you will continue exactly where you intended to go.