Which data structure follows the LIFO (Last In, First Out) principle?
Stack
#include <stdio.h>
int main() {
int x = 5;
if (x = 10) {
printf("Hello");
} else {
printf("World");
}
return 0;
}
hello
What is the binary representation of the decimal number 10?
1010
#include <stdio.h>
int main() {
// Displays on screen
for (int i = 10; i > 0; i++) {
printf("%d ", i);
}
return 0;
}
Infinite loop. The increment should be i--.
Which popular programming language is represented by a steaming coffee cup logo?
Java
What is the worst-case time complexity of Binary Search?
O(log N)
x = [1, 2, 3]
y = x
y.append(4)
print(x)
[1,2,3,4]
If 5 machines take 5 minutes to make 5 widgets, how long would it take 100 machines to make 100 widgets?
5 minutes
#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
// Displays on screen
for (int i = 1; i <= 5; i++) {
printf("%d ", arr[i]);
}
return 0;
}
array out of bound
What does the acronym "API" stand for?
Application Programming Interface
If you traverse a Binary Search Tree (BST) using "Left, Root, Right", in what order are the elements printed?
Sorted (Ascending) order
#include <stdio.h>
int main() {
int a = 0, b = 5;
if (a && ++b) {
printf("Inside ");
}
printf("%d", b);
return 0;
}
Output: 5
Explanation: Because of short-circuiting in logical &&, the compiler sees that a is 0 (false) and skips evaluating ++b entirely. Thus, b remains 5.
A lily pad doubles in size every day. If it takes 30 days to cover the entire pond, on what day does it cover half the pond?
Day 29
public class Main {
public static void main(String[] args) {
String s1 = "Hello";
String s2 = new String("Hello");
// Displays on screen
if (s1 == s2) {
System.out.println("Match");
} else {
System.out.println("No Match");
}
}
}
FIX: '==' compares memory addresses. Use .equals() to compare actual string values.
if (s1.equals(s2)) {
System.out.println("Match");
}
Which tech giant's original search engine prototype was called "BackRub" before they changed the name in 1997?
Which sorting algorithm has an average time complexity of O(N log N) but degrades to O(N^2) in its worst case (usually when the array is already sorted)?
Quick Sort
#include <stdio.h>
int f(int n) {
if (n <= 1) return 1;
return f(n - 1) + f(n - 1);
}
int main() {
printf("%d", f(3));
return 0;
}
Output: 4
Explanation:
f(1) = 1
f(2) = f(1) + f(1) = 1 + 1 = 2
f(3) = f(2) + f(2) = 2 + 2 = 4
You have 8 identical-looking balls, but one is slightly heavier. What is the minimum number of times you must use a balance scale to guarantee finding the heavy ball?
2 times
Explanation: Weigh 3 against 3. If they balance, weigh the remaining 2. If they don't, take the heavier group of 3, and weigh 1 against 1.
#include <stdio.h>
#include <string.h>
int main() {
// Displays on screen
char word[5];
strcpy(word, "Hello");
printf("%s", word);
return 0;
}
Answer: Buffer overflow. The array is too small to hold the string.
Explanation: In C, strings always end with a hidden null terminator character (\0) to tell the program where the string stops. "Hello" has 5 letters, so it actually requires an array size of 6 to store it safely!
The programming language C++ was developed in 1979. What was its original name before being renamed to C++?
C with Classes
Which graph algorithm is used to find the shortest path from a single source node to all other nodes in a weighted graph?
Dijkstra's Algorithm
#include <stdio.h>
int main() {
char c = 255;
c = c + 1;
printf("%d", c);
return 0;
}
OUTPUT: 0
Integer overflow! A standard 8-bit character can only hold values up to 255. Adding 1 causes it to wrap around back to 0.
Two trains start 100 km apart on the same track, driving toward each other at 50 km/h each. A super-fly starts at the front of one train and flies back and forth between the two trains at a constant speed of 80 km/h until the trains collide. What total distance does the fly travel?
80 km
#include <stdio.h>
int main() {
// Displays on screen
char *str = "Code";
str[0] = 'N';
printf("%s", str);
return 0;
}
Answer: Segmentation Fault. Attempting to modify a string literal.
Explanation: When you declare a string using a character pointer (char *str), the text "Code" is stored in the read-only section of the computer's memory. Trying to overwrite the 'C' with an 'N' will instantly crash the program!
// FIX: Declare it as a character array so it is stored in mutable Stack memory.
char str[] = "Code";
str[0] = 'N';
Which popular app was originally launched as a check-in app called "Burbn" before pivoting entirely to photo sharing?