DALL·E 2024-10-29 00 20 33 - A modern thumbnail for a blog post on common software development interview topics in Bangladesh, 2024  The image should feature a clean, professional

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
1def is_prime(n): 2 if n <= 1: 3 return False 4 for i in range(2, int(n ** 0.5) + 1): 5 if n % i == 0: 6 return False 7 return True 8 9 10print(is_prime(17)) # Output: True

2. Leap Year Calculation

python
1def is_leap(year): 2 return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0) 3 4print(is_leap(2024)) # Output: True

3. Fibonacci Sequence

python
1def fibonacci(n): 2 feb_seq = [0, 1] 3 while len(feb_seq) < n: 4 feb_seq.append(feb_seq[-2] + feb_seq[-1]) 5 return feb_seq[:n] 6 7print(fibonacci(5)) # Output: [0, 1, 1, 2, 3]

4. Factorial Calculator

python
1def factorial(n): 2 if n == 0 or n == 1: 3 return 1 4 return n * factorial(n - 1) 5 6print(factorial(5)) # Output: 120

5. Palindrome Checker

python
1def is_palindrom(s): 2 return s == s[::-1] 3 4print(is_palindrom('madam')) # Output: True 5print(is_palindrom('cat')) # Output: False

6. Armstrong number

python
1def is_armstrong(n): 2 digits = list(map(int, str(n))) 3 power = len(digits) 4 return n == sum([digit ** power for digit in digits]) 5 6print(is_armstrong(153)) # Output: True

7. Greatest Common Divisor (GCD)

python
1def gcd(a, b): 2 while b: 3 a, b = b, a % b 4 return a 5 6print(gcd(60, 48)) # Output: 12

8. Sum of Digits

python
1def sum_of_digits(n): 2 return sum(map(int, str(n))) 3 4print(sum_of_digits(12345)) # Output: 15

9. Reverse a String

python
1def reverse_string(s): 2 return s[::-1] 3 4print(reverse_string('madam')) # Output: madam

10. Bubble Sort

python
1def bubble_sort(arr): 2 n = len(arr) 3 for i in range(n): 4 for j in range(0, n-i-1): 5 if arr[j] > arr[j+1]: 6 arr[j], arr[j+1] = arr[j+1], arr[j] 7 return arr 8 9print(bubble_sort([0, 10, 11, 1, 2])) # Output: [0, 1, 2, 10, 11]

11. Binary Search

python
1def binary_search(arr, target): 2 low, high = 0, len(arr) - 1 3 4 while low <= high: 5 mid = (low + high) //2 6 if arr[mid] == target: 7 return mid 8 elif arr[mid] < target: 9 low = mid + 1 10 else: 11 high = mid - 1 12 return -1 13 14arr = [1, 2, 4, 5, 7, 9, 0, 10] 15target = 7 16 17print(binary_search(arr, target))

12. Find Max value in array

python
1def find_max(arr): 2 max_val = arr[0] 3 for num in arr[1:]: 4 if num > max_val: 5 max_val = num 6 return max_val 7 8print(find_max([1, 2, 4, 10, 11, 0])) # Output: 11

13. Write a Python function to find the second largest number in a list.

python
1def second_largest(numbers): 2 if len(numbers) < 2: 3 return None 4 unique_sorted = sorted(set(numbers), reverse=True) 5 return unique_sorted[1] if len(unique_sorted) > 1 else None 6 7# Example usage 8print(second_largest([10, 5, 8, 12, 3, 12, 7])) # Output: 10 9print(second_largest([1, 1, 1])) # Output: None

14. Remove duplicate in array

python
1arr = [1, 2, 2, 3, 4, 4, 5] 2arr = list(set(arr)) 3print(arr) # Output might be in a different order

14.1 Using List Comprehension with enumerate

python
1arr = [1, 2, 2, 3, 4, 4, 5] 2unique_arr = [item for index, item in enumerate(arr) if item not in arr[:index]] 3print(unique_arr) # Output: [1, 2, 3, 4, 5]

15. Swap value using a temporary variable

python
1a = 5 2b = 10 3temp = a 4a = b 5b = temp 6print(a) # Output: 10 7print(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:

  1. Encapsulation
  2. Abstraction
  3. Inheritance
  4. 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
1class Person: 2 def __init__(self, name, age): 3 self.__name = name # Private variable 4 self.__age = age # Private variable 5 6 7 # Getter method for name 8 def get_name(self): 9 return self.__name 10 11 12 # Setter method for name 13 def set_name(self, name): 14 self.__name = name 15 16 17 # Getter method for age 18 def get_age(self): 19 return self.__age 20 21 22 # Setter method for age 23 def set_age(self, age): 24 if age > 0: 25 self.__age = age 26 else: 27 print("Age cannot be negative.") 28 29 30# Usage 31person = Person("Alice", 25) 32print(person.get_name()) # Output: Alice 33person.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.

Example

python
1from abc import ABC, abstractmethod 2 3 4# Abstract class 5class Shape(ABC): 6 @abstractmethod 7 def area(self): 8 pass 9 10 11# Concrete class 12class Circle(Shape): 13 def __init__(self, radius): 14 self.radius = radius 15 16 17 # Implementing the abstract method 18 def area(self): 19 return 3.14 * self.radius * self.radius 20 21 22# Concrete class 23class Rectangle(Shape): 24 def __init__(self, width, height): 25 self.width = width 26 self.height = height 27 28 29 # Implementing the abstract method 30 def area(self): 31 return self.width * self.height 32 33 34# Usage 35circle = Circle(5) 36rectangle = Rectangle(4, 6) 37 38 39print("Circle area:", circle.area()) # Output: Circle area: 78.5 40print("Rectangle area:", rectangle.area()) # Output: Rectangle area: 24

3. Inheritance

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 class 2class Animal: 3 def __init__(self, name): 4 self.name = name 5 6 7 def make_sound(self): 8 print(f"{self.name} makes a sound") 9 10 11# Derived class 12class Dog(Animal): 13 def __init__(self, name, breed): 14 super().__init__(name) # Call the constructor of the base class 15 self.breed = breed 16 17 18 # Override the method 19 def make_sound(self): 20 print(f"{self.name} barks!") 21 22 23# Derived class 24class Cat(Animal): 25 def make_sound(self): 26 print(f"{self.name} meows!") 27 28 29# Usage 30dog = Dog("Buddy", "Golden Retriever") 31cat = Cat("Whiskers") 32 33 34dog.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
1class Calculator: 2 def add(self, a, b, c=None): 3 if c is not None: 4 return a + b + c 5 else: 6 return a + b 7 8 9calc = Calculator() 10print(calc.add(1, 2)) # 3 11print(calc.add(1, 2, 3)) # 6

Example of Method Overriding

python
1class Animal: 2 def speak(self): 3 return "Animal makes a sound" 4 5 6class Dog(Animal): 7 def speak(self): 8 return "Dog barks" 9 10 11dog = Dog() 12print(dog.speak()) # Outputs: Dog barks

BankAccount Class

python
1class BankAccount: 2 def __init__(self, balance=0): 3 self.balance = balance 4 5 def deposit(self, amount): 6 if amount > 0: 7 self.balance += amount 8 else: 9 raise ValueError("Deposit amount must be positive.") 10 11 def withdraw(self, amount): 12 if amount > self.balance: 13 raise ValueError("Insufficient funds.") 14 self.balance -= amount 15 16 def check_balance(self): 17 return self.balance

Shallow vs deep copy

  • 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 2 3list1 = [[1, 2], [3, 4]] 4shallow_copy = copy.copy(list1) 5deep_copy = copy.deepcopy(list1) 6 7list1[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.

Example Stack and Queue

python
1class Stack: 2 def __init__(self): 3 self.items = [] 4 5 def push(self, item): 6 self.items.append(item) 7 8 def pop(self): 9 return self.items.pop() if not self.is_empty() else None 10 11 def is_empty(self): 12 return len(self.items) == 0 13 14class Queue: 15 def __init__(self): 16 self.items = [] 17 18 def enqueue(self, item): 19 self.items.insert(0, item) 20 21 def dequeue(self): 22 return self.items.pop() if not self.is_empty() else None 23 24 def is_empty(self): 25 return len(self.items) == 0 26 27# Example usage 28stack = Stack() 29stack.push(1) 30stack.push(2) 31print(stack.pop()) # Output: 2 32 33queue = Queue() 34queue.enqueue('a') 35queue.enqueue('b') 36print(queue.dequeue()) # Output: 'a'

Reverse a Linked List

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
1class Node: 2 def __init__(self, data): 3 self.data = data 4 self.next = None 5 6class SinglyLinkedList: 7 def __init__(self): 8 self.head = None 9 10 def insert(self, data): 11 new_node = Node(data) 12 if not self.head: 13 self.head = new_node 14 else: 15 current = self.head 16 while current.next: 17 current = current.next 18 current.next = new_node 19 20 def display(self): 21 current = self.head 22 while current: 23 print(current.data, end=" -> ") 24 current = current.next 25 print("None") 26 27# Example usage 28sll = 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 class 2class Node: 3 def __init__(self, data): 4 self.data = data 5 self.next = None 6 7 8# Function to reverse a linked list 9def reverse_linked_list(head): 10 prev = None 11 current = head 12 13 # Iterate through the list 14 while current: 15 next_node = current.next # Store the next node 16 current.next = prev # Reverse the 'next' pointer 17 prev = current # Move prev to current node 18 current = next_node # Move to the next node 19 20 # After the loop, prev will be the new head 21 return prev 22 23 24# Helper function to print a linked list 25def print_linked_list(head): 26 current = head 27 while current: 28 print(current.data, end=" -> ") 29 current = current.next 30 print("None") 31 32 33# Example Usage 34# Creating a linked list: 1 -> 2 -> 3 -> 4 -> None 35head = Node(1) 36head.next = Node(2) 37head.next.next = Node(3) 38head.next.next.next = Node(4) 39 40 41print("Original Linked List:") 42print_linked_list(head) 43 44 45# Reversing the linked list 46new_head = reverse_linked_list(head) 47 48 49print("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

  1. Pick a pivot: select a pivot element from the array(commonly the first, last or middle element or a random one)
  2. 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.
  3. Recursion: Recursively apply the same process to the left and right sub-arrays
  4. Base case: Stop when the sub-arrays contain only one element (already sorted).

Example

python
1def quicksort(arr): 2 # Base case: array is empty or has one element 3 if len(arr) <= 1: 4 return arr 5 else: 6 pivot = arr[len(arr) // 2] # Choose the middle element as the pivot 7 left = [x for x in arr if x < pivot] # All elements less than pivot 8 middle = [x for x in arr if x == pivot] # All elements equal to pivot 9 right = [x for x in arr if x > pivot] # All elements greater than pivot 10 11 # Recursively apply quicksort to left and right sub-arrays 12 return quicksort(left) + middle + quicksort(right) 13 14# Example usage 15arr = [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.

1. Create (INSEART)

sql
1CREATE TABLE Employees ( 2 EmployeeID INT PRIMARY KEY, 3 FirstName VARCHAR(50), 4 LastName VARCHAR(50), 5 Salary DECIMAL(10, 2) 6); 7 8INSERT INTO Employees (EmployeeID, FirstName, LastName, Salary) 9VALUES (1, 'John', 'Doe', 50000.00);

2. Read (SELECT)

sql
1SELECT FirstName, LastName, Salary 2FROM Employees 3WHERE Salary > 40000;

3. Update(UPDATE)

sql
1UPDATE Employees 2SET Salary = 55000 3WHERE EmployeeID = 1;

4. Delete (DELETE)

sql
1DELETE FROM Employees 2WHERE EmployeeID = 1;

SQL Basics

JOIN

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: Orders 2OrderID | CustomerID | OrderDate 3-------------------------------- 41 | 1 | 2024-01-01 52 | 2 | 2024-02-01 6 7 8-- Table: Customers 9CustomerID | Name | City 10------------------------------ 111 | John Smith | New York 122 | Jane Doe | Los Angeles 13 14 15-- INNER JOIN Example 16SELECT Orders.OrderID, Customers.Name, Orders.OrderDate 17FROM Orders 18INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID; 19 20 21-- Result 22OrderID | Name | OrderDate 23-------------------------------- 241 | John Smith | 2024-01-01 252 | 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 3GROUP BY City 4HAVING COUNT(CustomerID) > 1;

Aggregate Functions

sql
1-- Count the number of employees 2SELECT COUNT(*) AS TotalEmployees 3FROM Employees; 4 5 6-- Find the maximum salary 7SELECT MAX(Salary) AS HighestSalary 8FROM Employees; 9 10 11-- Find the average salary 12SELECT AVG(Salary) AS AverageSalary 13FROM Employees; 14 15 16-- Find the total salary cost 17SELECT SUM(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 3 4# Sample data 5X = np.array([[1], [2], [3], [4], [5]]) 6y = np.array([2, 4, 5, 4, 5]) 7 8# Create and train the model 9model = LinearRegression() 10model.fit(X, y) 11 12# Make a prediction 13print(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:

  1. Data Collection:
  • Traffic flow patterns
  • Peak hours and congestion points
  • Current traffic light timings
  1. Analysis:
  • Identify bottlenecks and high-congestion areas
  • Analyze the relationship between light timings and traffic flow
  1. 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
  1. Implementation:
  • Start with a pilot program in high-congestion areas
  • Use machine learning algorithms to continuously improve the system
  1. 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.

Thank you very much for reading my blog. 🙌

Post date:
Read time: 15 min
Type: