Twenty-Eight (28) Beginner Whiteboard Programming Questions (Pseudo-Code)
Alright, let’s talk about whiteboarding. Look, I know it might seem scary at first – standing up there, marker in hand, trying to solve problems while someone watches. But here’s the thing: whiteboarding isn’t about being perfect. It’s about showing how you think through problems.
These 8 questions are your training wheels. They’re designed to help you practice the fundamental skills you’ll need when you’re standing in front of that whiteboard in an interview or code review. Each one covers a different concept, from basic string manipulation to more complex problem-solving patterns.
Don’t worry about memorizing the solutions – that’s not the point. The real skill is learning to break down problems, ask the right questions, and work through your logic step by step. I’ve seen students who can solve these problems in their sleep but freeze up during interviews because they never practiced the process of whiteboarding.
So grab a marker (or just use your computer screen), pick a problem, and talk through it out loud. Yes, out loud – even if you’re alone. Trust me, this is huge for building confidence.
Note: This version uses pseudo-code notation with while loops instead of for loops, and avoids range() function calls to help you think through the fundamental logic.
General Whiteboard Tips
- Start with clarifying questions - Ask about edge cases, input constraints
- Work through an example - Trace through the logic with sample input
- Write the function signature first - Define inputs and outputs clearly
- Think out loud - Explain your reasoning as you code
- Test your solution - Walk through your code with the example
- Discuss time/space complexity - Big O notation when relevant
- Consider edge cases - Empty inputs, negative numbers, etc.
- Keep code clean - Use meaningful variable names, proper indentation
Question 1: Reverse a String
Problem: Write a function that takes a string as input and returns the string reversed.
Example: Input: “hello” → Output: “olleh”
Solution:
FUNCTION reverse_string(s):
result = ""
index = length(s) - 1
WHILE index >= 0:
result = result + s[index]
index = index - 1
RETURN result
Whiteboard Tips: Start with the function signature, walk through an example, then implement step by step.
Question 2: Find the Maximum Number in an Array
Problem: Given an array of integers, find and return the largest number.
Example: Input: [3, 7, 2, 9, 1] → Output: 9
Solution:
FUNCTION find_max(arr):
IF length(arr) = 0:
RETURN null
max_num = arr[0]
index = 1
WHILE index < length(arr):
IF arr[index] > max_num:
max_num = arr[index]
index = index + 1
RETURN max_num
Whiteboard Tips: Always consider edge cases like empty arrays. Trace through with the example.
Question 3: Count Vowels in a String
Problem: Write a function that counts the number of vowels (a, e, i, o, u) in a given string.
Example: Input: “programming” → Output: 3
Solution:
FUNCTION count_vowels(s):
vowels = "aeiouAEIOU"
count = 0
index = 0
WHILE index < length(s):
char = s[index]
vowel_index = 0
WHILE vowel_index < length(vowels):
IF char = vowels[vowel_index]:
count = count + 1
BREAK
vowel_index = vowel_index + 1
index = index + 1
RETURN count
Whiteboard Tips: Define what counts as a vowel upfront. Consider case sensitivity.
Question 4: Check if a Number is Even or Odd
Problem: Write a function that determines if a given integer is even or odd.
Example: Input: 4 → Output: “even”, Input: 7 → Output: “odd”
Solution:
FUNCTION even_or_odd(num):
IF num MOD 2 = 0:
RETURN "even"
ELSE:
RETURN "odd"
Whiteboard Tips: This is simple but good for demonstrating basic conditional logic and modulo operator.
Question 5: Sum of Array Elements
Problem: Calculate the sum of all numbers in an array.
Example: Input: [1, 2, 3, 4, 5] → Output: 15
Solution:
FUNCTION array_sum(arr):
total = 0
index = 0
WHILE index < length(arr):
total = total + arr[index]
index = index + 1
RETURN total
Whiteboard Tips: Show the manual loop approach to demonstrate understanding of basic iteration.
Question 6: Find Duplicate Numbers
Problem: Given an array of integers, find and return the first number that appears more than once.
Example: Input: [1, 2, 3, 2, 4] → Output: 2
Solution:
FUNCTION find_first_duplicate(arr):
seen = empty_set()
index = 0
WHILE index < length(arr):
num = arr[index]
IF num IN seen:
RETURN num
ADD num TO seen
index = index + 1
RETURN null // No duplicates found
Whiteboard Tips: Explain the use of a set for O(1) lookup time. Discuss time/space complexity.
Question 7: Factorial Calculation
Problem: Write a function to calculate the factorial of a given positive integer.
Example: Input: 5 → Output: 120 (because 5! = 5 × 4 × 3 × 2 × 1)
Solution:
// Iterative approach
FUNCTION factorial_iterative(n):
IF n < 0:
RETURN null // Undefined for negative numbers
IF n = 0 OR n = 1:
RETURN 1
result = 1
current = 2
WHILE current <= n:
result = result * current
current = current + 1
RETURN result
// Recursive approach
FUNCTION factorial_recursive(n):
IF n < 0:
RETURN null
IF n = 0 OR n = 1:
RETURN 1
RETURN n * factorial_recursive(n - 1)
Whiteboard Tips: Great for showing both iterative and recursive thinking. Discuss base cases.
Question 8: Check if String is a Palindrome
Problem: Determine if a given string reads the same forwards and backwards (ignoring spaces and case).
Example: Input: “racecar” → Output: True, Input: “hello” → Output: False
Solution:
FUNCTION is_palindrome(s):
// Clean the string: remove spaces and convert to lowercase
cleaned = ""
index = 0
WHILE index < length(s):
char = s[index]
IF char != " ":
cleaned = cleaned + lowercase(char)
index = index + 1
// Two-pointer approach to check palindrome
left = 0
right = length(cleaned) - 1
WHILE left < right:
IF cleaned[left] != cleaned[right]:
RETURN false
left = left + 1
right = right - 1
RETURN true
Whiteboard Tips: Good for demonstrating string manipulation and two-pointer technique.
Key Pseudo-Code Elements Used
- FUNCTION name(parameters): - Function definition
- WHILE condition: - Loop structure
- IF/ELSE: - Conditional statements
- RETURN value - Function return
- MOD - Modulo operator
- length(array/string) - Get size
- empty_set() - Create empty set
- ADD item TO set - Set operations
- item IN set - Membership testing
- BREAK - Exit loop early
- lowercase(char) - String operations
This pseudo-code approach helps you focus on the logic flow without getting caught up in specific language syntax!
20 Additional Beginner Whiteboard Problems
Here are 20 more problems to help you build your whiteboarding confidence. Each one focuses on a specific concept you’ll see again and again in programming interviews and real-world coding.
Question 9: Remove Duplicates from Array
Problem: Given an array, return a new array with duplicate values removed.
Example: Input: [1, 2, 2, 3, 4, 4, 5] → Output: [1, 2, 3, 4, 5]
Solution:
FUNCTION remove_duplicates(arr):
result = empty_array()
seen = empty_set()
index = 0
WHILE index < length(arr):
current = arr[index]
IF current NOT IN seen:
ADD current TO result
ADD current TO seen
index = index + 1
RETURN result
WHY this works: We use a set to track what we’ve seen because set lookup is O(1) - much faster than searching through our result array every time. This is a classic trade-off: we use extra memory (the set) to make our algorithm faster.
Question 10: Find Second Largest Number
Problem: Find the second largest number in an array of integers.
Example: Input: [3, 1, 4, 1, 5, 9, 2] → Output: 5
Solution:
FUNCTION find_second_largest(arr):
IF length(arr) < 2:
RETURN null
largest = arr[0]
second_largest = null
index = 1
WHILE index < length(arr):
current = arr[index]
IF current > largest:
second_largest = largest
largest = current
ELSE IF current > second_largest AND current != largest:
second_largest = current
index = index + 1
RETURN second_largest
WHY this works: We track both the largest and second largest as we go. When we find a new largest, we “demote” the old largest to second place. This single-pass approach is more efficient than sorting the entire array.
Question 11: Count Occurrences of Character
Problem: Count how many times a specific character appears in a string.
Example: Input: “hello world”, ’l’ → Output: 3
Solution:
FUNCTION count_character(text, target_char):
count = 0
index = 0
WHILE index < length(text):
IF text[index] = target_char:
count = count + 1
index = index + 1
RETURN count
WHY this works: Simple linear search - we check every character once. This is O(n) which is optimal since we have to look at every character at least once to count them.
Question 12: Check if Array is Sorted
Problem: Determine if an array is sorted in ascending order.
Example: Input: [1, 2, 3, 4, 5] → Output: true, Input: [1, 3, 2, 4] → Output: false
Solution:
FUNCTION is_sorted(arr):
IF length(arr) <= 1:
RETURN true
index = 0
WHILE index < length(arr) - 1:
IF arr[index] > arr[index + 1]:
RETURN false
index = index + 1
RETURN true
WHY this works: We compare each element with the next one. If we ever find a pair that’s out of order, we know the array isn’t sorted. We stop at length-1 because we’re always checking index+1.
Question 13: Find Missing Number
Problem: Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the missing number.
Example: Input: [3, 0, 1] → Output: 2
Solution:
FUNCTION find_missing_number(arr):
n = length(arr)
expected_sum = n * (n + 1) / 2
actual_sum = 0
index = 0
WHILE index < length(arr):
actual_sum = actual_sum + arr[index]
index = index + 1
RETURN expected_sum - actual_sum
WHY this works: This uses the mathematical formula for the sum of consecutive integers: n(n+1)/2. We calculate what the sum should be, then what it actually is, and the difference is our missing number. Clever, right?
Question 14: Capitalize First Letter of Each Word
Problem: Given a string, capitalize the first letter of each word.
Example: Input: “hello world” → Output: “Hello World”
Solution:
FUNCTION capitalize_words(text):
result = ""
capitalize_next = true
index = 0
WHILE index < length(text):
char = text[index]
IF char = " ":
result = result + char
capitalize_next = true
ELSE IF capitalize_next:
result = result + uppercase(char)
capitalize_next = false
ELSE:
result = result + char
index = index + 1
RETURN result
WHY this works: We use a flag to track when we should capitalize the next letter. We set it to true at the start and after every space. This state-tracking approach is common in string processing problems.
Question 15: Two Sum Problem
Problem: Given an array and a target sum, find two numbers that add up to the target.
Example: Input: [2, 7, 11, 15], target = 9 → Output: [0, 1] (indices of 2 and 7)
Solution:
FUNCTION two_sum(arr, target):
complement_map = empty_map()
index = 0
WHILE index < length(arr):
current = arr[index]
complement = target - current
IF complement IN complement_map:
RETURN [complement_map[complement], index]
complement_map[current] = index
index = index + 1
RETURN null // No solution found
WHY this works: Instead of checking every pair (which would be O(n²)), we use a hash map to remember what we’ve seen. For each number, we calculate what its “complement” would need to be, then check if we’ve seen that complement before.
Question 16: Merge Two Sorted Arrays
Problem: Given two sorted arrays, merge them into one sorted array.
Example: Input: [1, 3, 5], [2, 4, 6] → Output: [1, 2, 3, 4, 5, 6]
Solution:
FUNCTION merge_sorted_arrays(arr1, arr2):
result = empty_array()
i = 0
j = 0
WHILE i < length(arr1) AND j < length(arr2):
IF arr1[i] <= arr2[j]:
ADD arr1[i] TO result
i = i + 1
ELSE:
ADD arr2[j] TO result
j = j + 1
// Add remaining elements from arr1
WHILE i < length(arr1):
ADD arr1[i] TO result
i = i + 1
// Add remaining elements from arr2
WHILE j < length(arr2):
ADD arr2[j] TO result
j = j + 1
RETURN result
WHY this works: We use the “two-pointer” technique. Since both arrays are already sorted, we can compare the front elements and always take the smaller one. This is the foundation of merge sort!
Question 17: Find Longest Word
Problem: Find the longest word in a sentence.
Example: Input: “The quick brown fox jumps” → Output: “quick” (or “brown” or “jumps”)
Solution:
FUNCTION find_longest_word(sentence):
longest_word = ""
current_word = ""
index = 0
WHILE index < length(sentence):
char = sentence[index]
IF char = " ":
IF length(current_word) > length(longest_word):
longest_word = current_word
current_word = ""
ELSE:
current_word = current_word + char
index = index + 1
// Don't forget the last word!
IF length(current_word) > length(longest_word):
longest_word = current_word
RETURN longest_word
WHY this works: We build words character by character, keeping track of the longest one we’ve seen. The tricky part is remembering to check the last word after the loop ends - there’s no space after it!
Question 18: Check if Strings are Anagrams
Problem: Determine if two strings are anagrams (contain the same characters in different order).
Example: Input: “listen”, “silent” → Output: true
Solution:
FUNCTION are_anagrams(str1, str2):
IF length(str1) != length(str2):
RETURN false
char_count = empty_map()
index = 0
// Count characters in first string
WHILE index < length(str1):
char = str1[index]
IF char IN char_count:
char_count[char] = char_count[char] + 1
ELSE:
char_count[char] = 1
index = index + 1
// Subtract characters from second string
index = 0
WHILE index < length(str2):
char = str2[index]
IF char NOT IN char_count:
RETURN false
char_count[char] = char_count[char] - 1
IF char_count[char] < 0:
RETURN false
index = index + 1
RETURN true
WHY this works: We count all characters in the first string, then “subtract” characters from the second string. If they’re anagrams, we’ll end up with all counts at zero. This is more efficient than sorting both strings.
Question 19: Find First Non-Repeating Character
Problem: Find the first character that appears exactly once in a string.
Example: Input: “abccba” → Output: null, Input: “abcabc” → Output: null, Input: “abcdcba” → Output: “d”
Solution:
FUNCTION first_non_repeating_char(text):
char_count = empty_map()
index = 0
// Count all characters
WHILE index < length(text):
char = text[index]
IF char IN char_count:
char_count[char] = char_count[char] + 1
ELSE:
char_count[char] = 1
index = index + 1
// Find first character with count = 1
index = 0
WHILE index < length(text):
char = text[index]
IF char_count[char] = 1:
RETURN char
index = index + 1
RETURN null // No non-repeating character found
WHY this works: We need two passes: first to count everything, then to find the first character with count=1. We can’t do it in one pass because we need to know the full count before deciding.
Question 20: Rotate Array
Problem: Rotate an array to the right by k positions.
Example: Input: [1, 2, 3, 4, 5], k=2 → Output: [4, 5, 1, 2, 3]
Solution:
FUNCTION rotate_array(arr, k):
IF length(arr) = 0:
RETURN arr
k = k MOD length(arr) // Handle k > array length
result = empty_array()
// Add elements from position (length - k) to end
index = length(arr) - k
WHILE index < length(arr):
ADD arr[index] TO result
index = index + 1
// Add elements from start to position (length - k)
index = 0
WHILE index < length(arr) - k:
ADD arr[index] TO result
index = index + 1
RETURN result
WHY this works: Rotating right by k is the same as taking the last k elements and putting them at the front. We use modulo to handle cases where k is larger than the array length.
Question 21: Valid Parentheses
Problem: Check if parentheses in a string are balanced.
Example: Input: “((()))” → Output: true, Input: “(()” → Output: false
Solution:
FUNCTION valid_parentheses(text):
stack = empty_array()
index = 0
WHILE index < length(text):
char = text[index]
IF char = "(":
ADD char TO stack
ELSE IF char = ")":
IF length(stack) = 0:
RETURN false
REMOVE last element FROM stack
index = index + 1
RETURN length(stack) = 0
WHY this works: We use a stack (array used as stack) to track opening parentheses. Each closing parenthesis should match with the most recent unmatched opening one. This is a classic stack problem pattern.
Question 22: Find Intersection of Two Arrays
Problem: Find elements that appear in both arrays.
Example: Input: [1, 2, 3], [2, 3, 4] → Output: [2, 3]
Solution:
FUNCTION find_intersection(arr1, arr2):
set1 = empty_set()
result = empty_array()
index = 0
// Add all elements from arr1 to set
WHILE index < length(arr1):
ADD arr1[index] TO set1
index = index + 1
// Check arr2 elements against set1
index = 0
WHILE index < length(arr2):
current = arr2[index]
IF current IN set1:
ADD current TO result
REMOVE current FROM set1 // Avoid duplicates
index = index + 1
RETURN result
WHY this works: We convert one array to a set for O(1) lookup, then check each element of the second array. We remove elements from the set after adding them to avoid duplicates in the result.
Question 23: Remove Element from Array
Problem: Remove all instances of a specific value from an array.
Example: Input: [3, 2, 2, 3], value=3 → Output: [2, 2]
Solution:
FUNCTION remove_element(arr, target):
result = empty_array()
index = 0
WHILE index < length(arr):
current = arr[index]
IF current != target:
ADD current TO result
index = index + 1
RETURN result
WHY this works: Simple filtering - we create a new array with only the elements we want to keep. This is the clearest approach for beginners, though you could also do it “in-place” with two pointers.
Question 24: Find Peak Element
Problem: Find an element that is greater than its neighbors.
Example: Input: [1, 2, 3, 1] → Output: 3 (index 2)
Solution:
FUNCTION find_peak(arr):
IF length(arr) = 0:
RETURN null
IF length(arr) = 1:
RETURN 0
// Check first element
IF arr[0] > arr[1]:
RETURN 0
// Check last element
IF arr[length(arr) - 1] > arr[length(arr) - 2]:
RETURN length(arr) - 1
// Check middle elements
index = 1
WHILE index < length(arr) - 1:
IF arr[index] > arr[index - 1] AND arr[index] > arr[index + 1]:
RETURN index
index = index + 1
RETURN null
WHY this works: We handle the edge cases (first and last elements) separately since they only have one neighbor. For middle elements, we check both neighbors. This is O(n) but teaches the important concept of handling edge cases.
Question 25: Convert to Lowercase
Problem: Convert all uppercase letters in a string to lowercase.
Example: Input: “Hello World” → Output: “hello world”
Solution:
FUNCTION to_lowercase(text):
result = ""
index = 0
WHILE index < length(text):
char = text[index]
IF char >= "A" AND char <= "Z":
// Convert to lowercase by adding 32 to ASCII value
lowercase_char = char + 32
result = result + lowercase_char
ELSE:
result = result + char
index = index + 1
RETURN result
WHY this works: We use the ASCII relationship between uppercase and lowercase letters. Uppercase ‘A’ is 65, lowercase ‘a’ is 97 - a difference of 32. This shows how character encoding works under the hood.
Question 26: Move Zeros to End
Problem: Move all zeros in an array to the end while maintaining the order of other elements.
Example: Input: [0, 1, 0, 3, 12] → Output: [1, 3, 12, 0, 0]
Solution:
FUNCTION move_zeros_to_end(arr):
result = empty_array()
zero_count = 0
index = 0
// Add all non-zero elements first
WHILE index < length(arr):
IF arr[index] != 0:
ADD arr[index] TO result
ELSE:
zero_count = zero_count + 1
index = index + 1
// Add zeros to the end
WHILE zero_count > 0:
ADD 0 TO result
zero_count = zero_count - 1
RETURN result
WHY this works: We collect all non-zero elements first, counting the zeros as we go. Then we add the right number of zeros to the end. This maintains the relative order of non-zero elements.
Question 27: Find Minimum in Rotated Sorted Array
Problem: Find the minimum element in a rotated sorted array.
Example: Input: [4, 5, 6, 7, 0, 1, 2] → Output: 0
Solution:
FUNCTION find_min_rotated(arr):
IF length(arr) = 0:
RETURN null
min_val = arr[0]
index = 1
WHILE index < length(arr):
IF arr[index] < min_val:
min_val = arr[index]
index = index + 1
RETURN min_val
WHY this works: For beginners, the simple linear search is easiest to understand and implement correctly. While binary search would be more efficient, this O(n) solution demonstrates the core logic without getting complex.
Question 28: Count Words in String
Problem: Count the number of words in a string.
Example: Input: “Hello world programming” → Output: 3
Solution:
FUNCTION count_words(text):
IF length(text) = 0:
RETURN 0
word_count = 0
in_word = false
index = 0
WHILE index < length(text):
char = text[index]
IF char != " ":
IF NOT in_word:
word_count = word_count + 1
in_word = true
ELSE:
in_word = false
index = index + 1
RETURN word_count
WHY this works: We track whether we’re currently “in a word” or not. When we encounter a non-space character after being outside a word, we’ve found a new word. This handles multiple spaces correctly.
Key Problem-Solving Patterns You’ve Learned
- Two-Pointer Technique - Used in palindrome checking, merging arrays
- Hash Map/Set for Fast Lookup - Used in duplicates, anagrams, two sum
- Stack for Matching - Used in parentheses validation
- State Tracking - Used in word capitalization, word counting
- Mathematical Formulas - Used in missing number problem
- Edge Case Handling - Critical in all problems
- Single Pass vs Multiple Pass - Different strategies for different problems
Remember, the goal isn’t to memorize these solutions - it’s to understand the thinking process behind them. Each problem teaches you a pattern you can apply to similar problems!