Aquila Innovations

Coding Practice

Daily coding practice that builds the problem-solving ability required in technical rounds.

Curriculum

Data Structures Algorithms Coding Challenges Competitive Programming Basics Debugging Techniques

Sample Questions & Answers

100 practice question(s) with answers.

All Modules
01

What is a variable in programming?

A named box that stores a value you can read and change.

age = 21
name = "Amit"
print(age, name)
02

How do you print output in Python?

Use the print function.

print("Hello, World!")
03

How do you print output in C?

Use printf.

#include <stdio.h>
int main() {
    printf("Hello, World!\n");
    return 0;
}
04

How do you print output in Java?

Use System.out.println.

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
05

What is a data type?

It defines what kind of value a variable holds.

age = 21        # int
score = 9.5     # float
name = "Amit"   # string
print(type(age), type(score), type(name))
06

What is an if statement?

Runs code only when a condition is true.

n = 10
if n % 2 == 0:
    print("Even")
else:
    print("Odd")
07

How do you check if a number is even?

Check the remainder with the modulo operator.

def is_even(n):
    return n % 2 == 0
print(is_even(10))   # True
08

What is a for loop?

Repeats a block a fixed number of times.

for i in range(5):
    print(i)   # prints 0 1 2 3 4
09

What is a while loop?

Repeats while a condition is true.

i = 1
while i <= 5:
    print(i)
    i += 1
10

How do you sum the first 10 numbers?

Use a loop or a formula.

total = sum(range(1, 11))
print(total)   # 55
11

How do you find the maximum of two numbers?

Use max or a comparison.

def max_of(a, b):
    return a if a > b else b
print(max_of(4, 9))   # 9
12

What is a function?

A reusable named block of code.

def greet(name):
    return "Hello, " + name
print(greet("Riya"))
13

What is recursion?

A function that calls itself with a base case.

def fact(n):
    if n <= 1:          # base case
        return 1
    return n * fact(n - 1)
print(fact(5))          # 120
14

What is a list in Python?

An ordered collection of values.

nums = [3, 1, 2]
nums.append(4)
print(sorted(nums))   # [1, 2, 3, 4]
15

How do you iterate over a list?

Use a for loop.

for x in [10, 20, 30]:
    print(x)
16

How do you find the sum of a list?

Use the sum function.

print(sum([1, 2, 3, 4, 5]))   # 15
17

How do you find the length of a list or string?

Use len.

print(len([1, 2, 3]))   # 3
print(len("hello"))     # 5
18

How do you reverse a string?

Use slicing.

s = "hello"
print(s[::-1])   # olleh
19

How do you check if a string is a palindrome?

Compare the string with its reverse.

def is_pal(s):
    return s == s[::-1]
print(is_pal("madam"))   # True
20

How do you count the vowels in a string?

Loop and count.

def count_vowels(s):
    return sum(1 for c in s.lower() if c in "aeiou")
print(count_vowels("hello"))   # 2
21

What is a dictionary in Python?

A key-value store.

d = {"name": "Amit", "age": 21}
print(d["name"])
d["city"] = "Hyderabad"
22

How do you check if a key exists in a dictionary?

Use the in operator.

d = {"a": 1}
print("a" in d)   # True
23

What is a set?

An unordered collection of unique values.

s = {1, 2, 2, 3}
print(s)   # {1, 2, 3}
24

How do you remove duplicates from a list?

Convert to a set.

nums = [1, 2, 2, 3, 3]
print(list(set(nums)))   # [1, 2, 3]
25

How do you swap two numbers?

Use a tuple unpack.

a, b = 5, 10
a, b = b, a
print(a, b)   # 10 5
26

What is bubble sort?

Repeatedly swap adjacent out-of-order items.

def bubble_sort(arr):
    for i in range(len(arr)):
        for j in range(len(arr) - 1 - i):
            if arr[j] > arr[j + 1]:
                arr[j], arr[j + 1] = arr[j + 1], arr[j]
    return arr
print(bubble_sort([4, 2, 5, 1]))   # [1, 2, 4, 5]
27

What is selection sort?

Repeatedly pick the smallest and move it to the front.

def selection_sort(arr):
    for i in range(len(arr)):
        m = min(range(i, len(arr)), key=arr.__getitem__)
        arr[i], arr[m] = arr[m], arr[i]
    return arr
print(selection_sort([4, 2, 5, 1]))
28

What is binary search?

Search a sorted list by halving the range each step.

def binary_search(arr, key):
    lo, hi = 0, len(arr) - 1
    while lo <= hi:
        mid = (lo + hi) // 2
        if arr[mid] == key: return mid
        if arr[mid] < key: lo = mid + 1
        else: hi = mid - 1
    return -1
print(binary_search([1, 3, 5, 7, 9], 7))   # 3
29

What is linear search?

Check each element until you find the target.

def linear_search(arr, key):
    for i, v in enumerate(arr):
        if v == key: return i
    return -1
print(linear_search([4, 2, 5, 1], 5))   # 2
30

What is the Fibonacci sequence?

Each term is the sum of the previous two.

def fib(n):
    a, b = 0, 1
    for _ in range(n):
        a, b = b, a + b
    return a
print([fib(i) for i in range(8)])   # [0,1,1,2,3,5,8,13]
31

How do you check if a number is prime?

Test divisibility up to its square root.

import math
def is_prime(n):
    if n < 2: return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0: return False
    return True
print(is_prime(29))   # True
32

How do you find the factorial of a number?

Loop or recursion.

def factorial(n):
    r = 1
    for i in range(2, n + 1):
        r *= i
    return r
print(factorial(5))   # 120
33

How do you find the GCD of two numbers?

Use the Euclidean algorithm.

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
print(gcd(12, 18))   # 6
34

What is the LCM of two numbers?

Product divided by GCD.

def lcm(a, b):
    return (a * b) // gcd(a, b)
def gcd(a, b):
    while b: a, b = b, a % b
    return a
print(lcm(4, 6))   # 12
35

How do you reverse a list in place?

Use slicing or a loop.

arr = [1, 2, 3, 4]
arr.reverse()
print(arr)   # [4, 3, 2, 1]
36

How do you find the second largest number?

Sort and index, or scan once.

nums = [5, 1, 9, 3, 9]
print(sorted(set(nums))[-2])   # 5
37

What is a stack?

LIFO structure, last in first out.

stack = []
stack.append(1)
stack.append(2)
print(stack.pop())   # 2
38

What is a queue?

FIFO structure, first in first out.

from collections import deque
q = deque([1, 2])
q.append(3)
print(q.popleft())   # 1
39

How do you convert a string to a list of characters?

Use list.

print(list("hello"))   # ['h','e','l','l','o']
40

How do you join a list into a string?

Use join.

print("-".join(["a", "b", "c"]))   # a-b-c
41

How do you split a sentence into words?

Use split.

print("hello world".split())   # ['hello', 'world']
42

What is exception handling?

Catching and handling runtime errors gracefully.

try:
    x = 10 // 0
except ZeroDivisionError:
    print("Cannot divide by zero")
43

What is a try-except block?

Code to attempt an operation and handle errors.

try:
    n = int("abc")
except ValueError:
    n = 0
print(n)   # 0
44

What is a class?

A blueprint for creating objects.

class Student:
    def __init__(self, name):
        self.name = name
    def hello(self):
        return "Hi " + self.name
s = Student("Riya")
print(s.hello())
45

What is an object?

An instance of a class with its own data.

46

What is inheritance?

A class deriving properties from another class.

class Animal:
    def speak(self): return "..."
class Dog(Animal):
    def speak(self): return "Woof"
print(Dog().speak())
47

What is a constructor?

A special method that runs when an object is created, like __init__.

48

What is a method?

A function that belongs to a class or object.

49

What is an attribute?

A variable that belongs to a class or object.

50

What is OOP?

Organising code around objects with encapsulation, inheritance, polymorphism and abstraction.

51

What is encapsulation?

Hiding internal data and exposing safe methods to use it.

52

What is polymorphism?

The ability of different objects to respond to the same method in their own way.

53

What is abstraction?

Showing only essential details and hiding complexity.

54

What is a module?

A file of reusable code you can import.

import math
print(math.sqrt(16))   # 4.0
55

What is the difference between import and from import?

Import brings the module; from import brings a name directly.

from math import sqrt
print(sqrt(9))
56

What are keyword arguments?

Arguments passed by name.

def greet(name, greeting="Hi"):
    return greeting + " " + name
print(greet("Amit", greeting="Hello"))
57

What is a default parameter?

A parameter with a default value used when none is passed.

58

What is a lambda function?

A small anonymous one-line function.

add = lambda a, b: a + b
print(add(3, 4))   # 7
59

What is a generator?

A function that yields values one at a time.

def countdown(n):
    while n > 0:
        yield n
        n -= 1
print(list(countdown(3)))   # [3, 2, 1]
60

What is a list comprehension?

A compact way to build lists.

squares = [x * x for x in range(5)]
print(squares)   # [0, 1, 4, 9, 16]
61

What is a string method?

A built-in operation on strings.

s = "Hello"
print(s.upper(), s.lower(), s.strip())
62

How do you count characters in a string?

Use count.

print("banana".count("a"))   # 3
63

What is the difference between = and ==?

= assigns a value; == compares values.

64

What is the ternary operator?

A shorthand if-else.

n = 7
print("Even" if n % 2 == 0 else "Odd")
65

What is a for-else in Python?

The else runs if the loop finishes without a break.

66

What is the pass statement?

A no-op used where syntax requires a statement.

67

What is a type cast?

Converting one data type to another.

print(int("42") + 1)   # 43
print(str(42) + "!")    # 42!
68

How do you read user input?

Use input.

name = input("Enter your name: ")
print("Hello", name)
69

What is a file read operation?

Reading the contents of a file.

with open("data.txt") as f:
    print(f.read())
70

How do you write to a file?

Open in write mode.

with open("out.txt", "w") as f:
    f.write("Hello")
71

What is the with statement for files?

It opens and automatically closes files safely.

72

What is a runtime error?

An error that happens while the program runs.

73

What is a syntax error?

An error because code does not follow language rules.

74

What is a logic error?

The code runs but gives the wrong result.

75

What is a debugger used for?

To step through code and inspect values to find bugs.

76

What is time complexity?

How runtime grows with input size, written as Big O.

77

What is O(1) complexity?

Constant time, independent of input size.

78

What is O(n) complexity?

Linear time, proportional to input size.

79

What is O(n log n) complexity?

Log-linear time, typical of good sorting like merge sort.

80

What is O(n squared)?

Quadratic time, typical of nested loops like bubble sort.

81

What is the complexity of binary search?

O(log n).

82

What is the complexity of linear search?

O(n).

83

What is the complexity of accessing an array element by index?

O(1).

84

What is the complexity of sorting an unsorted array with bubble sort?

O(n squared).

85

What is space complexity?

How memory usage grows with input size.

86

What is Big O notation?

A notation for describing growth rates of algorithms.

87

What is a pivot in quicksort?

An element chosen to partition the array into smaller and larger parts.

88

What is merge sort?

A divide-and-conquer sort that merges sorted halves.

def merge_sort(a):
    if len(a) <= 1: return a
    mid = len(a) // 2
    l = merge_sort(a[:mid]); r = merge_sort(a[mid:])
    res = []
    while l and r:
        res.append(l.pop(0) if l[0] < r[0] else r.pop(0))
    return res + l + r
print(merge_sort([4, 2, 5, 1, 3]))
89

What is the difference between stable and unstable sort?

A stable sort keeps the order of equal elements; an unstable one may not.

90

What is a greedy algorithm?

Makes the best local choice at each step hoping for the best global result.

91

What is dynamic programming?

Solving problems by combining solutions to overlapping subproblems and storing them.

92

What is memoization?

Storing results of expensive calls to reuse them.

from functools import lru_cache
@lru_cache
def fib(n):
    return n if n < 2 else fib(n-1) + fib(n-2)
print(fib(40))
93

What is a two-sum problem?

Find two numbers that add to a target.

def two_sum(nums, target):
    seen = {}
    for i, v in enumerate(nums):
        if target - v in seen:
            return [seen[target - v], i]
        seen[v] = i
    return []
print(two_sum([2, 7, 11, 15], 9))   # [0, 1]
94

What is string comparison?

Comparing strings by their characters and order.

95

How do you check if two strings are anagrams?

Sort both and compare.

def is_anagram(a, b):
    return sorted(a) == sorted(b)
print(is_anagram("listen", "silent"))   # True
96

What is a 0/1 knapsack problem?

Choose items with weights and values to maximise value within capacity.

97

What is a linked list node?

An element that holds data and a pointer to the next node.

98

How do you traverse a linked list?

Follow the next pointers from the head until null.

99

What is a circular list?

A list where the last node points back to the head.

100

What is a graph traversal?

Visiting all nodes in a graph, using BFS or DFS.

Need Help With Coding Practice?

Join the next training batch for guided practice, mock tests and personal feedback.

Register