Data Structures and Algorithms Questions Junior Interviews Use
Junior interviews test a narrow slice of data structures and algorithms: arrays, hash maps, stacks, and simple sorting. You do not need to grind hundreds of LeetCode problems. The questions below cover what actually comes up, with solutions in Python and JavaScript.
Array questions
Q: Two Sum. Given an array and a target, find two numbers that add up to the target.
# Python
def two_sum(nums: list[int], target: int) -> list[int]:
seen = {}
for i, num in enumerate(nums):
complement = target - num
if complement in seen:
return [seen[complement], i]
seen[num] = i
return []
print(two_sum([2, 7, 11, 15], 9)) # [0, 1]The brute force approach checks every pair (O(n^2)). The hash map approach above runs in O(n) time and O(n) space. Interviewers want to see you improve from brute force to optimal.
Q: Find the maximum subarray sum (Kadane's algorithm).
// JavaScript
function maxSubarraySum(arr: number[]): number {
let maxSum = arr[0];
let currentSum = arr[0];
for (let i = 1; i < arr.length; i++) {
currentSum = Math.max(arr[i], currentSum + arr[i]);
maxSum = Math.max(maxSum, currentSum);
}
return maxSum;
}
console.log(maxSubarraySum([-2, 1, -3, 4, -1, 2, 1, -5, 4])); // 6Hash map questions
Q: Check if two strings are anagrams.
# Python
from collections import Counter
def is_anagram(s: str, t: str) -> bool:
return Counter(s) == Counter(t)
print(is_anagram("listen", "silent")) # True
print(is_anagram("hello", "world")) # FalseCounter builds a frequency map. Two anagrams have identical frequency maps. Time complexity: O(n).
Q: Find the first non-repeating character in a string.
// JavaScript
function firstUnique(s: string): string | null {
const counts = new Map<string, number>();
for (const char of s) {
counts.set(char, (counts.get(char) || 0) + 1);
}
for (const char of s) {
if (counts.get(char) === 1) return char;
}
return null;
}
console.log(firstUnique("aabbcdd")); // "c"Stack questions
Q: Valid parentheses. Check if a string of brackets is balanced.
# Python
def is_valid(s: str) -> bool:
stack = []
pairs = {"(": ")", "[": "]", "{": "}"}
for char in s:
if char in pairs:
stack.append(char)
elif not stack or pairs[stack.pop()] != char:
return False
return len(stack) == 0
print(is_valid("()[]{}")) # True
print(is_valid("([)]")) # False
print(is_valid("{[]}")) # TruePush opening brackets onto the stack. When you see a closing bracket, pop the stack and check if it matches. This is the most common stack question in interviews.
Sorting and searching
Q: Implement binary search.
// JavaScript
function binarySearch(arr: number[], target: number): number {
let left = 0;
let right = arr.length - 1;
while (left <= right) {
const mid = Math.floor((left + right) / 2);
if (arr[mid] === target) return mid;
if (arr[mid] < target) left = mid + 1;
else right = mid - 1;
}
return -1; // not found
}
console.log(binarySearch([1, 3, 5, 7, 9], 7)); // 3Binary search only works on sorted arrays. It cuts the search space in half on each step, giving O(log n) time.
Q: Explain the difference between O(n) and O(n log n).
O(n) means the work grows linearly with input size. O(n log n) grows slightly faster. For 1,000 items, O(n) does about 1,000 operations and O(n log n) does about 10,000. For 1,000,000 items, O(n) does 1,000,000 and O(n log n) does about 20,000,000. The difference matters at scale but both are considered efficient.
How to study without burning out
The mistake most junior developers make is trying to solve 500 problems on LeetCode. This leads to burnout and pattern-matching without understanding.
A better approach:
- Learn the core patterns: two pointers, sliding window, hash map lookups, BFS/DFS, and stack-based processing
- Solve 3 to 5 problems per pattern until you can recognise which pattern fits a new problem
- For each problem, first write the brute force solution, then optimise. Interviewers value this thought process
- Practice explaining your approach out loud. Interviews test communication as much as code
For most junior roles at Kenyan companies, the bar is lower than FAANG interviews. Solid fundamentals and clear communication beat grinding 500 problems every time.
Frequently Asked Questions
- Do junior developers really need to know algorithms?
- At a basic level, yes. You need to understand time complexity, know when to use a hash map vs an array, and solve simple array/string manipulation problems. You do not need dynamic programming or graph algorithms for most junior roles.
- Should I solve problems in Python or JavaScript?
- Use the language you are most comfortable with. Python is popular for its clean syntax. JavaScript is fine too. Some interviewers let you choose; others specify the language. If in doubt, ask before the interview.
- How many problems should I practice before an interview?
- Quality over quantity. Doing 30 to 50 well-understood problems across the core patterns is more effective than rushing through 200 without fully understanding the solutions.
Ready to build real-world apps?
Join the McTaba Labs full-stack marathon. Ship 8 production apps with M-Pesa, USSD, and WhatsApp integrations, and get career support until placement.
See Programs