Common Topics for Software Development Interviews and Written Tests in Bangladesh, 2024
I recently applied for some entry-level or mid-level software development positions in October 2024 and had several interviews. In my experience, they usually begin by asking questions on fundamental CSE topics. These topics are also commonly covered in the written exams and include questions relevant to the job post.
For write code on pen and paper without an IDE
1. Prime Number Check
python
1defis_prime(n):2if n <=1:3returnFalse4for i inrange(2,int(n **0.5)+1):5if n % i ==0:6returnFalse7returnTrue8910print(is_prime(17))# Output: True
2. Leap Year Calculation
python
1defis_leap(year):2return(year %4==0and year %100!=0)or(year %400==0)34print(is_leap(2024))# Output: True
1deffactorial(n):2if n ==0or n ==1:3return14return n * factorial(n -1)56print(factorial(5))# Output: 120
5. Palindrome Checker
python
1defis_palindrom(s):2return s == s[::-1]34print(is_palindrom('madam'))# Output: True5print(is_palindrom('cat'))# Output: False
6. Armstrong number
python
1defis_armstrong(n):2 digits =list(map(int,str(n)))3 power =len(digits)4return n ==sum([digit ** power for digit in digits])56print(is_armstrong(153))# Output: True
7. Greatest Common Divisor (GCD)
python
1defgcd(a, b):2while b:3 a, b = b, a % b
4return a
56print(gcd(60,48))# Output: 12
1deffind_max(arr):2 max_val = arr[0]3for num in arr[1:]:4if num > max_val:5 max_val = num
6return max_val
78print(find_max([1,2,4,10,11,0]))# Output: 11
13. Write a Python function to find the second largest number in a list.
1a =52b =103temp = a
4a = b
5b = temp
6print(a)# Output: 107print(b)# Output: 5
OOP
Object-oriented programming (OOP) is a computer programming model that organises software design around data, or objects, rather than functions and logic. An object can be defined as a data field that has unique attributes and behaviour.
Object-oriented programming (OOP) has four pillars of concept:
Encapsulation
Abstraction
Inheritance
Polymorphism - Overloading and Overriding
1. Encapsulation
Encapsulation is the concept of bunding data (attributes) and methods(functions) that work on the data into a single unit, usually in the form of a class. It restricts direct access to certain components and ensures control over how data is accessed and modified.
Key point: Private attributes (denoted by an double underscore in __ python), access or modify the private attributes via getter and setter methods.
Example
python
1classPerson:2def__init__(self, name, age):3 self.__name = name # Private variable4 self.__age = age # Private variable567# Getter method for name8defget_name(self):9return self.__name
101112# Setter method for name13defset_name(self, name):14 self.__name = name
151617# Getter method for age18defget_age(self):19return self.__age
202122# Setter method for age23defset_age(self, age):24if age >0:25 self.__age = age
26else:27print("Age cannot be negative.")282930# Usage31person = Person("Alice",25)32print(person.get_name())# Output: Alice33person.set_age(30)34print(person.get_age())# Output: 30
2. Abstraction
Abstraction focuses on exposing only the necessary details while hiding the complexities. It is achieved using abstract classes or interfaces.
Key point: Abstract class contains one or more abstract methods (Methods without implementation). These abstract methods must be implemented by any concrete class ( a non-abstract class) that inherits from the abstract class.
Inheritance allows one class to inherit properties and methods from another class. This promotes code reuse and a hierarchical class structure.
Key point: Base class(parent class), the class whose properties and methods are inherited. Derived class(child class), the class that inherits properties and methods from the base class.
Example
python
1# Base class2classAnimal:3def__init__(self, name):4 self.name = name
567defmake_sound(self):8print(f"{self.name} makes a sound")91011# Derived class12classDog(Animal):13def__init__(self, name, breed):14super().__init__(name)# Call the constructor of the base class15 self.breed = breed
161718# Override the method19defmake_sound(self):20print(f"{self.name} barks!")212223# Derived class24classCat(Animal):25defmake_sound(self):26print(f"{self.name} meows!")272829# Usage30dog = Dog("Buddy","Golden Retriever")31cat = Cat("Whiskers")323334dog.make_sound()# Output: Buddy barks!35cat.make_sound()# Output: Whiskers meows!
4. Polymorphism
Polymorphism allows objects of different classes to be treated as objects of a common super class. It enables the same method to perform different behaviours based on the object calling it.
Key point: Method Overriding: Redefining a method in a derived class that exist in the base class. Method Overloading: Having multiple methods with the same name but different parameters (not supported natively in Python, but can be mimicked using default arguments or other techniques).
Example of Method Overloading
python
1classCalculator:2defadd(self, a, b, c=None):3if c isnotNone:4return a + b + c
5else:6return a + b
789calc = Calculator()10print(calc.add(1,2))# 311print(calc.add(1,2,3))# 6
Example of Method Overriding
python
1classAnimal:2defspeak(self):3return"Animal makes a sound"456classDog(Animal):7defspeak(self):8return"Dog barks"91011dog = Dog()12print(dog.speak())# Outputs: Dog barks
Shallow copy: Copies the reference to object not the objects themselves
Deep copy: Copies the object and all nested objects, creating independent duplicates
python
1import copy
23list1 =[[1,2],[3,4]]4shallow_copy = copy.copy(list1)5deep_copy = copy.deepcopy(list1)67list1[0][0]=99# Affects shallow_copy but not deep_copy
Data Structures and Algorithms
Stack
A stack is a linear data structure that follows the LIFO (Last in, First Out) principle. The last element added to the stack in the first one to be removed.
Common Operations:
Push: Add an element to the top of the stack.
Pop: Remove and return the top element from the stack.
Peek: View the top element without removing it.
Real-world example:
Think of a stack of plates. The last plate you put on the top is the first one you take off.
Usages: Undo functionality in software like text editors or drawing programs
Queue
A queue is a linear data structure that follows the FIFO(First in, First Out) principle. The first element added to the queue is the first one to be removed.
Common operations:
Enqueue: Add an element to the end of the queue
Dequeue: Remove an element to the first.
Real-world example:
Think of a line at a bank counter. The first person in line gets served first.
Usages: Printer queue (Jobs are prints in the order they arrive) or handling requests in a web server.
Linked List Overview: A linked list is a data structure in which each element (node) contains a data part and a reference (or pointer) to the next node in the sequence. Linked lists are useful for dynamic data storage where the size can change over time.
Types
Singly Linked list: Each node points to the next node.
Doubly Linked list: Each node has pointers to both the next and previous nodes.
Implementing a Singly Linked List
python
1classNode:2def__init__(self, data):3 self.data = data
4 self.next=None56classSinglyLinkedList:7def__init__(self):8 self.head =None910definsert(self, data):11 new_node = Node(data)12ifnot self.head:13 self.head = new_node
14else:15 current = self.head
16while current.next:17 current = current.next18 current.next= new_node
1920defdisplay(self):21 current = self.head
22while current:23print(current.data, end=" -> ")24 current = current.next25print("None")2627# Example usage28sll = SinglyLinkedList()29sll.insert(1)30sll.insert(2)31sll.insert(3)32sll.display()# Output: 1 -> 2 -> 3 -> None
Reversing a Singly Linked list
To reverse a linked list, we need to iterate through the list and reverse the next pointers of the nodes so that they point to the previous node.
Example
python
1# Define a Node class2classNode:3def__init__(self, data):4 self.data = data
5 self.next=None678# Function to reverse a linked list9defreverse_linked_list(head):10 prev =None11 current = head
1213# Iterate through the list14while current:15 next_node = current.next# Store the next node16 current.next= prev # Reverse the 'next' pointer17 prev = current # Move prev to current node18 current = next_node # Move to the next node1920# After the loop, prev will be the new head21return prev
222324# Helper function to print a linked list25defprint_linked_list(head):26 current = head
27while current:28print(current.data, end=" -> ")29 current = current.next30print("None")313233# Example Usage34# Creating a linked list: 1 -> 2 -> 3 -> 4 -> None35head = Node(1)36head.next= Node(2)37head.next.next= Node(3)38head.next.next.next= Node(4)394041print("Original Linked List:")42print_linked_list(head)434445# Reversing the linked list46new_head = reverse_linked_list(head)474849print("Reversed Linked List:")50print_linked_list(new_head)
Complexity
Time Complexity: O(n) where n is the number of nodes in the linked list (we visit each node once)
Space Complexity: O(1), because we only use a few extra pointers.
Quicksort Algorithm and Time Complexity
Quicksort is a divide-and-conquer sorting algorithm that selects a “pivot” element and partitions the array into two sub-arrays: One with elements less than the pivot and the other with elements greater than the pivot. The process is recursively applied to both sub-arrays.
Steps
Pick a pivot: select a pivot element from the array(commonly the first, last or middle element or a random one)
Partitioning: Rearrange the array such that all elements less than the pivot are on the left side and all elements greater than the pivot are on the right side.
Recursion: Recursively apply the same process to the left and right sub-arrays
Base case: Stop when the sub-arrays contain only one element (already sorted).
Example
python
1defquicksort(arr):2# Base case: array is empty or has one element3iflen(arr)<=1:4return arr
5else:6 pivot = arr[len(arr)//2]# Choose the middle element as the pivot7 left =[x for x in arr if x < pivot]# All elements less than pivot8 middle =[x for x in arr if x == pivot]# All elements equal to pivot9 right =[x for x in arr if x > pivot]# All elements greater than pivot1011# Recursively apply quicksort to left and right sub-arrays12return quicksort(left)+ middle + quicksort(right)1314# Example usage15arr =[3,6,8,10,1,2,1]16sorted_arr = quicksort(arr)17print("Sorted Array:", sorted_arr)
Complexity
Time
Base case: O(n log n) occurs when the pivot consistently divides the array into balanced sub-arrays
Average case: O(n log n) as the array is usually split in a relatively balanced manner.
Worst case: O(n^2) occurs when the pivot divides the array into very unbalanced sub-arrays
Worst case example:
If the array is already sorted, and we always pick the first or last element as the pivot, we repeatedly partition the array into one large sub-array and one empty one, leading to O(n^2) behaviour.
Space
O(log n) Due to the recursion stack in the best and average cases.
O(n) in the worst case because of the recursion depth when the pivot leads to highly unbalanced partitions.
CRUD operations in SQL
CRUD operations in SQL refer to the basic operations we can perform on a database: Create, Read, Update, and Delete.
There are different types of joins, but the most common is the INNER JOIN, which returns only matching rows between two tables.
sql
1-- Table: Orders2OrderID | CustomerID | OrderDate
3--------------------------------41|1|2024-01-0152|2|2024-02-01678-- Table: Customers9CustomerID | Name | City
10------------------------------111| John Smith | New York
122| Jane Doe | Los Angeles
131415-- INNER JOIN Example16SELECT Orders.OrderID, Customers.Name, Orders.OrderDate
17FROM Orders
18INNERJOIN Customers ON Orders.CustomerID = Customers.CustomerID;192021-- Result22OrderID | Name | OrderDate
23--------------------------------241| John Smith |2024-01-01252| Jane Doe |2024-02-01
GROUP BY and HAVING
Group by is used to group records with the same values.
Having is used to filter records after Group by is applied
sql
1SELECT City,COUNT(CustomerID)AS NumberOfCustomers
2FROM Customers
3GROUPBY City
4HAVINGCOUNT(CustomerID)>1;
Aggregate Functions
sql
1-- Count the number of employees2SELECTCOUNT(*)AS TotalEmployees
3FROM Employees;456-- Find the maximum salary7SELECTMAX(Salary)AS HighestSalary
8FROM Employees;91011-- Find the average salary12SELECTAVG(Salary)AS AverageSalary
13FROM Employees;141516-- Find the total salary cost17SELECTSUM(Salary)AS TotalSalaryCost
18FROM Employees;
ACID Properties
ACID is an acronym that stands for Atomicity, Consistency, Isolation, and Durability. These are key properties of database transactions to ensure data integrity.
ACID Explained:
Atomicity: Ensures that all operations within a transaction are completed successfully, or none of them are. If one part of a transaction fails, the entire transaction is rolled back.
Example: Transferring money from one bank account to another – either both accounts are updated, or none are.
Consistency: Ensures that a transaction brings the database from one valid state to another, maintaining all predefined rules (such as constraints, triggers).
Example: If a field is marked as NOT NULL, no transaction should allow inserting a NULL value.
Isolation: Ensures that concurrent execution of transactions leads to the same state as if the transactions were executed sequentially.
Example: If two users try to book the last seat in a cinema simultaneously, only one transaction should succeed.
Durability: Once a transaction has been committed, it remains so, even in the case of a system failure (e.g., power outage).
Example: After transferring money, the updated balances should remain persistent even if the system crashes.
Basic AI Knowledge
Question: Explain the difference between supervised and unsupervised learning in machine learning.
Supervised Learning:
Uses labeled data
The algorithm learns to predict outputs based on input features
Examples: classification, regression
Use case: spam detection, price prediction
Unsupervised Learning:
Uses unlabeled data
The algorithm finds patterns or structures in the data
Examples: clustering, dimensionality reduction
Use case: customer segmentation, anomaly detection
Python example of supervised learning (Linear Regression):
python
1from sklearn.linear_model import LinearRegression
2import numpy as np
34# Sample data5X = np.array([[1],[2],[3],[4],[5]])6y = np.array([2,4,5,4,5])78# Create and train the model9model = LinearRegression()10model.fit(X, y)1112# Make a prediction13print(model.predict([[6]]))# Predict for X = 6
Analytical Skills
Question: Given a scenario: "A city wants to optimize its traffic light system to reduce congestion." Describe your approach to analyzing this problem and proposing a solution.
Approach:
Data Collection:
Traffic flow patterns
Peak hours and congestion points
Current traffic light timings
Analysis:
Identify bottlenecks and high-congestion areas
Analyze the relationship between light timings and traffic flow
Propose Solution:
Implement an AI-based adaptive traffic control system
Use real-time data from sensors and cameras
Dynamically adjust light timings based on current traffic conditions
Implementation:
Start with a pilot program in high-congestion areas
Use machine learning algorithms to continuously improve the system
Evaluation:
Compare traffic flow before and after implementation
Measure reduction in average wait times and overall congestion
These may not be enough, but they cover 70-80% of frequently asked topics. Start with these related topics. If you plan on applying, learn more about these areas.