Technical Aptitude
300 practice questions for Technical Aptitude, spanning Programming Fundamentals, Data Structures, Algorithms, and 4 more topics, each with a full worked solution and a Basic, Intermediate, or Advanced difficulty tag.
Programming Fundamentals
0/20 practicedWhat does this C snippet print:
int x = 5; printf("%d", x++);?
Solution
x++ is post-increment, so printf reads the current value of x (5) before the increment happens, then x becomes 6 afterward.
In Python, what does
print(3 * "hello")output?
Solution
Multiplying a string by an integer repeats it that many times: 3 * "hello" gives "hellohellohello".
Trace this Java code. What is x afterward:
int x = 10; x += 5;?
Solution
x += 5 is shorthand for x = x + 5, so x becomes 10 + 5 = 15.
What gets printed by this C++ snippet:
int a = 3, b = 4; cout << a + b;?
Solution
a + b evaluates to 3 + 4 = 7, and cout writes 7.
What effect does this Python code have:
x = [1, 2, 3]; x.append(4)?
Solution
append(4) adds 4 onto the end of list x, turning it into [1, 2, 3, 4].
What is the output of this C code:
int x = 8; printf("%d", x >> 1);?
Solution
x >> 1 shifts the bits right by one place. 8 in binary is 1000, which becomes 0100, i.e. 4.
What does this Java line output:
boolean x = true; System.out.println(!x);?
Solution
The ! operator flips a boolean, so !x turns true into false.
Work out the output of this Python code:
x = 10; y = 3; print(x // y)?
Solution
// performs floor (integer) division, discarding the remainder: 10 // 3 = 3.
What does this C++ snippet print:
int x = 5; if(x > 3) cout << "Yes"; else cout << "No";?
Solution
Since 5 > 3 is true, the if branch runs and prints Yes.
What is printed by this Python loop:
for i in range(3): print(i)?
Solution
range(3) produces the sequence 0, 1, 2, and the loop prints each one on its own line.
What does this C code output:
int x = 3; printf("%d", x & 1);?
Solution
x & 1 is a bitwise AND. 3 is 11 in binary and 1 is 01; ANDing them gives 01, i.e. 1.
What is printed by this Java snippet:
int x = 7; System.out.println(x % 2);?
Solution
% computes the remainder: 7 % 2 leaves a remainder of 1.
What is the output of this Python code:
x = [1, 2]; x.pop(0); print(x)?
Solution
pop(0) removes the element at index 0 (which is 1), leaving the list [2].
What does this C++ code print:
int x = 4; cout << ++x;?
Solution
++x is pre-increment: x becomes 5 first, and that updated value is what gets printed.
What is the output of this C snippet:
int x = 5; printf("%d", x | 2);?
Solution
x | 2 is a bitwise OR. 5 is 101 in binary and 2 is 010; ORing them gives 111, i.e. 7.
What does this Python code output:
x = {1, 2, 2}; print(len(x))?
Solution
Sets automatically drop duplicate values, so {1, 2, 2} collapses to {1, 2}, and len reports 2.
What is printed by this Java code:
String s = "Hello"; System.out.println(s.length());?
Solution
length() returns the number of characters in the string; "Hello" has 5.
What is the output of this C++ loop:
int x = 10; while(x > 8) { cout << x << " "; x--; }?
Solution
The loop keeps running while x > 8, printing 10 then 9 before x drops to 8 and the loop stops.
What does this Python line output:
x = 5; print(x ** 2)?
Solution
** is the exponentiation operator: 5 ** 2 = 25.
What is printed by this C code:
int x = 6; printf("%d", x ^ 3);?
Solution
x ^ 3 is a bitwise XOR. 6 is 110 and 3 is 011; XORing gives 101, i.e. 5.
Data Structures
0/20 practicedHow fast is element access on an array, in Big-O terms?
Solution
An array lets you jump straight to any index, so access takes constant time.
For a singly linked list, what's the time complexity of inserting a new node at the head?
Solution
Inserting at the head is just repointing the head reference, which takes constant time regardless of list size.
Follow this Python stack code. What's printed:
s = []; s.append(1); s.append(2); s.pop(); print(s)?
Solution
Using a list as a stack (LIFO): append pushes 1 then 2, pop removes the most recent item (2), leaving [1].
For a queue, what's the final element order after: enqueue(1), enqueue(2), dequeue(), enqueue(3)?
Solution
A queue is FIFO: 1 and 2 are enqueued, dequeue() removes the oldest item (1), then 3 is enqueued, leaving 2, 3 in order.
What's the time complexity of a linear search through an unsorted array of n elements?
Solution
Without any ordering to exploit, the search may have to inspect every element, giving n comparisons in the worst case.
In a binary tree rooted at level 0, what's the largest possible number of nodes at level k?
Solution
Each level can have at most twice as many nodes as the one above it, so level k can hold up to 2^k nodes.
What does this Python list operation produce:
x = [1, 2, 3]; x.insert(1, 4); print(x)?
Solution
insert(1, 4) places 4 at index 1, shifting the rest over, giving [1, 4, 2, 3].
What's the amortized time complexity of appending to the end of a dynamic array?
Solution
Occasional resizing aside, appends average out to constant time, since resizes happen rarely relative to the number of appends.
In a size-5 circular queue, after enqueue(1, 2, 3), dequeue(), enqueue(4), what's at the front?
Solution
After enqueuing 1, 2, 3, dequeue removes 1. Enqueuing 4 afterward doesn't change the front, which is now 2.
For a balanced binary tree with 7 nodes, how tall is it?
Solution
A balanced tree's height follows ⌊log₂(n)⌋; for n = 7 that's ⌊log₂(7)⌋ = 2, spanning levels 0 through 2.
What does this Python dictionary lookup return:
d = {1: 'a', 2: 'b'}; print(d[1])?
Solution
Looking up key 1 in the dictionary returns its associated value, 'a'.
What's the time complexity of removing the last node from a singly linked list of n nodes?
Solution
Without a tail pointer's predecessor known, you must walk to the second-to-last node first, which takes O(n).
On this stack: push(1), push(2), pop(), push(3), what ends up on top?
Solution
Pushing 1 then 2, popping removes 2, and pushing 3 puts 3 on top.
For a balanced binary search tree with n nodes, what's the search time complexity?
Solution
A balanced BST's height grows logarithmically with n, so search takes O(log n).
What is the result of this Python set operation:
s = {1, 2, 3}; s.add(4); print(s)?
Solution
add(4) inserts 4 into the set, giving {1, 2, 3, 4}.
What's the space complexity of storing a binary tree with n nodes?
Solution
Every node carries its own data plus two child pointers, so total storage scales linearly: O(n).
Trace this queue sequence: enqueue(1, 2), dequeue(), enqueue(3, 4), dequeue(). What's the front now?
Solution
Enqueue 1, 2; dequeue removes 1; enqueue 3, 4; dequeue removes 2. The front is now 3.
On average, what's the time complexity of inserting a key into a hash table?
Solution
With a decent hash function distributing keys evenly, insertion averages out to O(1).
What is the output of this Python list method:
x = [1, 2, 3]; x.remove(2); print(x)?
Solution
remove(2) deletes the first occurrence of 2 from the list, leaving [1, 3].
For a binary tree of height h, what's the largest possible number of nodes it can hold?
Solution
Summing the maximum node count across every level from 0 to h gives 2^(h+1) - 1.
Algorithms
0/20 practicedWhat's the time complexity of bubble sort on n elements?
Solution
Bubble sort's nested comparison-and-swap loops give it O(n²) time.
What does this Python search return:
x = [3, 1, 4]; print(x.index(4))?
Solution
index(4) returns the position of the first 4 in the list, which is index 2.
What's the time complexity of binary search over a sorted array of n elements?
Solution
Each comparison cuts the remaining search space in half, giving O(log n).
Trace this recursive C factorial function. What does it print:
int fact(int n) { if(n == 0) return 1; return n * fact(n-1); } printf("%d", fact(3));?
Solution
fact(3) unwinds as 3 × fact(2) = 3 × 2 × fact(1) = 3 × 2 × 1 = 6.
What's the space complexity of a recursive factorial implementation?
Solution
Each recursive call adds a frame to the call stack, so n calls use O(n) stack space.
What does this Python sort produce:
x = [5, 2, 8]; print(sorted(x))?
Solution
sorted(x) returns a brand-new sorted list without touching the original: [2, 5, 8].
What's the time complexity of scanning for the maximum in an unsorted array of n elements?
Solution
Without any ordering to rely on, every element has to be checked once: O(n).
Trace this recursive C summing function. What's printed:
int sum(int n) { if(n == 0) return 0; return n + sum(n-1); } printf("%d", sum(4));?
Solution
sum(4) expands to 4 + sum(3) = 4 + 3 + sum(2) = 4 + 3 + 2 + sum(1) = 4 + 3 + 2 + 1 = 10.
What's the time complexity of selection sort on n elements?
Solution
Selection sort scans for the minimum on every pass, giving it O(n²) overall.
What does this Python slice produce:
x = [1, 2, 3]; print(x[::-1])?
Solution
The slice [::-1] walks the list backward, reversing it to [3, 2, 1].
What's the time complexity of testing membership in a sorted array via binary search?
Solution
Binary search halves the candidate range each step, so it runs in O(log n).
What does this C++ loop compute:
int x = 5; for(int i = 1; i <= 3; i++) x += i; cout << x;?
Solution
The loop adds 1, 2, and 3 onto x in turn: 5 + 1 + 2 + 3 = 11.
What's the space complexity of bubble sort?
Solution
Bubble sort swaps elements in place and needs no extra structures, so its space use is constant: O(1).
What does this Python code output:
x = [1, 2, 3]; print(sum(x))?
Solution
sum(x) totals the list's elements: 1 + 2 + 3 = 6.
What's the time complexity of inserting a value into a sorted array of n elements while keeping it sorted?
Solution
Making room for the new element means shifting the ones after it, which costs O(n).
What does this C conditional print:
int a = 3, b = 5; if(a > b) printf("%d", a); else printf("%d", b);?
Solution
3 > 5 is false, so the else branch runs and prints b, which is 5.
What's the time complexity of merging two already-sorted arrays of sizes m and n?
Solution
Merging walks through both arrays once, comparing and copying as it goes: O(m + n).
What does this Python string method return:
x = "abc"; print(x.upper())?
Solution
upper() returns an all-caps version of the string: "ABC".
What's the time complexity of reversing an array of n elements in place?
Solution
Swapping elements from opposite ends toward the middle touches each pair once, giving O(n).
What does this C++ snippet print:
int x = 4; x *= 3; cout << x;?
Solution
x *= 3 multiplies x by 3: 4 * 3 = 12.
Database Basics
0/10 practicedWhat does this SQL statement do:
SELECT * FROM table_name;?
Solution
It pulls back every column for every row stored in table_name.
What does
SELECT name FROM employees WHERE salary > 50000;return?
Solution
It returns the name values for employee rows whose salary is above 50000.
What guarantee does the SQL
PRIMARY KEYconstraint provide?
Solution
It guarantees every value in that column is both unique and never null.
What does
SELECT COUNT(*) FROM students WHERE age = 20;return?
Solution
It counts how many rows in students have age equal to 20.
What does the statement
DELETE FROM table_name WHERE id = 1;do?
Solution
It deletes whichever row has id equal to 1.
What role does the SQL
JOINclause play?
Solution
It combines rows across two or more tables based on how a shared column relates them.
What effect does
INSERT INTO users (name, age) VALUES ('Alice', 25);have?
Solution
It inserts a new row into users with name set to 'Alice' and age set to 25.
What does
SELECT MAX(salary) FROM employees;return?
Solution
It returns whichever salary value in the table is the largest.
What does the SQL
WHEREclause do?
Solution
It narrows down the returned rows to just those matching a given condition.
What does
UPDATE products SET price = 100 WHERE id = 5;do?
Solution
It changes price to 100 for the row whose id is 5.
Computer Networks
0/10 practicedWhy does every device on a network need an IP address?
Solution
An IP address is what uniquely identifies a device so it can be found on the network.
Which port does HTTP traffic normally use?
Solution
HTTP defaults to port 80.
What does the abbreviation TCP stand for?
Solution
Transmission Control Protocol; it's designed to guarantee reliable delivery of data.
What job does DNS do on a network?
Solution
It converts human-readable domain names, like google.com, into the IP addresses computers actually use.
How do IPv4 and IPv6 differ?
Solution
IPv4 addresses are 32 bits (e.g. 192.168.0.1); IPv6 addresses are 128 bits, giving vastly more room for addresses.
What does "bandwidth" mean in networking?
Solution
It's the upper limit on how much data a connection can carry per unit of time.
What does a router actually do inside a network?
Solution
It forwards packets of data between different networks.
What's the default subnet mask for a Class C address?
Solution
Class C reserves 24 bits for the network portion, giving a mask of 255.255.255.0.
What does the ARP protocol handle?
Solution
It resolves IP addresses down to the corresponding MAC addresses.
What does UDP stand for, and how is it different from TCP?
Solution
User Datagram Protocol; it's quicker than TCP but sacrifices reliability, since it skips TCP's error-checking.
Operating Systems
0/10 practicedAt a high level, what does an operating system actually do?
Solution
It manages the machine's hardware and software resources and gives the user a way to interact with them.
What exactly is a "process" in an OS's terms?
Solution
It's a running instance of a program, complete with its own memory space and resources.
What's the scheduler's job inside an OS?
Solution
It decides how CPU time gets divided among competing processes so execution stays efficient.
What's a deadlock, in operating-systems terms?
Solution
It's a standoff where processes are each holding a resource another needs, so none of them can proceed.
What does "virtual memory" mean?
Solution
It's a technique that borrows disk space to effectively extend available RAM, letting larger programs run.
What does a file system actually manage inside an OS?
Solution
It organizes how data is stored and retrieved on disk.
What's a "thread" in the context of an operating system?
Solution
It's a lighter-weight execution unit that shares its parent process's memory space.
Why do interrupts exist in an OS?
Solution
They let the CPU know it needs to stop and handle something urgent, like hardware input.
How does a kernel differ from a shell?
Solution
The kernel is the OS's core, managing resources directly; the shell is the interface a user interacts with.
What's the page table's role in virtual memory?
Solution
It keeps the mapping between virtual addresses and where they actually live in physical memory.
AI/ML Foundations
0/10 practicedWhat defines supervised learning in machine learning?
Solution
The model learns from labeled examples (input/output pairs), so it can predict outputs for new inputs.
Why do ML models use a loss function?
Solution
It quantifies how far off the model's predictions are from the real answers, giving optimization something to minimize.
What's meant by "overfitting" in machine learning?
Solution
It's when a model fits the training data too closely, memorizing its noise, and then performs poorly on unseen data.
What is a "feature" in the context of ML?
Solution
It's one of the input variables the model uses to make its predictions.
Why split data into training and test sets before building a model?
Solution
The training set is what the model learns from; the test set checks how well it generalizes to data it hasn't seen.
What is a neuron, in the context of a neural network?
Solution
It's a small computational unit that takes inputs, applies weights to them, and produces an output.
What does the activation function contribute in a neural network?
Solution
It introduces non-linearity, determining whether and how strongly a neuron fires.
What is gradient descent used for in ML?
Solution
It's an optimization method that nudges the model's parameters step by step to shrink the loss function.
What characterizes unsupervised learning in ML?
Solution
The model looks for structure or patterns in data that has no predefined output labels.
Why normalize features before training an ML model?
Solution
Scaling features onto a common range tends to improve how well the model trains.
Topics
Log in to save which questions you've practiced across every category.
Frequently asked questions
What does the Technical Aptitude practice set cover?
300 questions across 3 difficulty levels (100 each of Basic, Intermediate, and Advanced), spanning Programming Fundamentals, Data Structures, Algorithms, and 4 more topics.
Are the answers and solutions shown?
Yes. Every question has a full worked solution and final answer, hidden behind a "Show Answer" toggle so you can genuinely self-test before checking.
Is it free to use?
Yes. Browsing every problem on this page is completely free, with no account required. Creating a free DevsUnite account lets you save your checked-off progress, star favorites, and add personal notes that sync across devices.
Do I need an account to track my progress?
You can read and solve every problem without logging in. An account is only required to mark a problem as done, star it, or add a note. Those actions save to your account instead of resetting on refresh.