Coding & technical

Online Coding Test — free practice test

An online coding test is a remotely administered, automatically graded programming round, usually hosted on a platform such as HackerRank, Codility or HackerEarth. You solve one or more problems in a browser editor against hidden test cases within a time limit. It is the most common way companies screen developers at scale before scheduling interviews.

Updated 2026-06-19 · 8 marked questions on this page, no signup · 5 worked sample questions with answers · AI-scored mock tests run inside the OnJob app.

Free practice test · no signup

Take the practice test now

8 multiple-choice questions in the style of a real online coding test, marked instantly on this page. Every answer comes with the working, so a wrong pick tells you which concept to revise. Nothing to install, no account, no email.

Q1. What is the worst-case time complexity of binary search on a sorted array of n elements?
Show the worked answer

Correct answer: O(log n). Each comparison discards half the remaining range, so the number of steps is the number of times n can be halved — log₂ n.

Q2. In the worst case, how many comparisons does binary search need on 1,000 sorted items?
Show the worked answer

Correct answer: 10. 2⁹ = 512 and 2¹⁰ = 1,024, so ten halvings are enough to cover 1,000 items. Nine would only guarantee 512.

Q3. A problem states n ≤ 1,000,000. Which solution is safe inside a typical time limit?
Show the worked answer

Correct answer: O(n log n). At n = 10⁶, O(n log n) is roughly 2×10⁷ operations. O(n²) is 10¹², which no judge will finish; the exponential and factorial options are far worse.

Q4. What is the sum of all integers from 1 to 100?
Show the worked answer

Correct answer: 5,050. The closed form is n(n+1)/2, so 100 × 101 ÷ 2 = 5,050. Knowing it lets you verify a loop’s output in O(1).

Q5. Kadane's algorithm solves which problem, and in what time?
Show the worked answer

Correct answer: Maximum contiguous subarray sum, in O(n). Kadane's keeps a running sum, resets it whenever it turns negative, and tracks the best sum seen — one pass, so O(n).

Q6. Which data structure gives average O(1) lookup by key?
Show the worked answer

Correct answer: Hash map. A hash map computes the slot directly from the key. A sorted array needs O(log n) via binary search, a linked list O(n), and a heap only gives O(1) access to its root.

Q7. What is the worst-case time complexity of quicksort?
Show the worked answer

Correct answer: O(n²). On an already-sorted input with a bad pivot choice, each partition removes only one element, giving n levels of O(n) work. The O(n log n) figure is the average case.

Q8. Which structure processes elements first-in, first-out?
Show the worked answer

Correct answer: Queue. A queue removes from the end it did not add to, so the oldest element leaves first. A stack is last-in, first-out.

Key takeaways

  • An online coding test is a remotely administered, automatically graded programming round, usually hosted on a platform such as HackerRank, Codility or HackerEarth.
  • A Online Coding Test typically covers: Problem solving, Language and IDE, Multiple-choice technical, Time management.
  • You can take a 8-question practice test on this page — it marks itself instantly and shows the working for every answer, with no signup.
What it measures

What an online coding test covers

Problem solving

Implementing correct, efficient solutions to algorithmic problems against hidden tests.

Language and IDE

Working comfortably in the platform's browser editor and your chosen language.

Multiple-choice technical

Many tests bundle MCQs on output prediction, complexity and core CS concepts.

Time management

Allocating minutes per problem and submitting partial solutions before the timer ends.

Practice questions

5 sample online coding test questions with answers

Genuinely-correct, worked examples. Try each one before opening the answer , then go back to the marked practice test above and sit it against the clock .

Q1. What is printed by a loop that sums integers from 1 to 100?

Answer: The sum of 1 to n is n(n+1)/2, so for n = 100 it is 100 × 101 ÷ 2 = 5050. Knowing the closed-form formula lets you verify a loop's output and solve the problem in O(1) instead of O(n).

Q2. Given an array, how do you find the maximum subarray sum?

Answer: Use Kadane's algorithm: track a running sum, resetting it to the current element whenever it goes negative, and keep the best sum seen. It finds the maximum contiguous subarray sum in a single O(n) pass.

Q3. How do you remove duplicates from an array of integers efficiently?

Answer: Insert every element into a hash set, which automatically discards duplicates, then read the set back out. This is O(n) time and O(n) space. If the array is sorted, you can instead do it in place with two pointers in O(1) extra space.

Q4. What is the difference between O(n) and O(n²) and why does it matter on large inputs?

Answer: O(n) grows in direct proportion to input size, while O(n²) grows with the square. For n = 1,000, that is 1,000 versus 1,000,000 operations — so an O(n²) solution can time out on the large hidden test cases that an O(n) one passes.

Q5. How would you count the number of vowels in a string?

Answer: Make a single pass over the string, and for each character check if it belongs to the set {a, e, i, o, u} (case-insensitive), incrementing a counter when it does. This is an O(n) one-pass solution.

Step by step

How to prepare for an online coding test

  1. 1

    Read every problem fully before coding any, then solve the easiest ones first to lock in guaranteed points.

  2. 2

    Test your code against the sample cases the platform gives, plus your own edge cases, before submitting.

  3. 3

    Watch the constraints: an input size up to a million signals you need an O(n) or O(n log n) solution, not O(n²).

  4. 4

    Submit partial, working solutions — many platforms award points per passing test case, so never leave a problem blank.

  5. 5

    Practise on the exact platform the company uses so the editor, custom-input box and submission flow feel familiar on test day.

Frequently asked questions

Everything you need to know before you create your free profile.

Create My Free Profile

What is an online coding test?

+

Remote, auto-graded coding rounds run on platforms like HackerRank and Codility — what to expect and how to pass them. This page covers what it measures, 5 worked sample questions with answers, and 5 ways to prepare — then you can sit a timed, scored version in OnJob's free AI mock tests.

What is printed by a loop that sums integers from 1 to 100?

+

The sum of 1 to n is n(n+1)/2, so for n = 100 it is 100 × 101 ÷ 2 = 5050. Knowing the closed-form formula lets you verify a loop's output and solve the problem in O(1) instead of O(n).

Given an array, how do you find the maximum subarray sum?

+

Use Kadane's algorithm: track a running sum, resetting it to the current element whenever it goes negative, and keep the best sum seen. It finds the maximum contiguous subarray sum in a single O(n) pass.

Can I take the test on this page, or do I have to sign up?

+

You can take it right here. The practice test above has 8 multiple-choice questions, marks itself the moment you press "Check my score", and shows the working for every answer. No account, no email and no download. Signing up is only needed for OnJob's AI-scored mock tests, which grade written and spoken answers and can earn a verified skill badge.

Are these online coding test questions free to practise?

+

Yes. Every sample question and answer on this page is free to read. OnJob's AI mock tests are free to start (₹0) — you get up to 3 mock tests and 1 real, badge-earning test every month, with instant scoring and feedback. Pro (₹99/month) adds more attempts and deeper analytics.

Free forever — no credit card

Practise your online coding test under real conditions

The test above is self-marked and free. The next step is feedback: take a scored AI mock test on OnJob, see exactly where you stand against the role you want, then apply to AI-matched jobs in one click.