Ace Your
Technical Interview
20 HR questions. 175 coding problems. 8 languages.
HR & Behavioral Questions
20Introductory
3 questionsTips
- →Keep it professional — 2 to 3 minutes max
- →Follow a structure: present → past → future
- →Highlight achievements, not just responsibilities
- →Practice with a timer until it feels natural
Do's
- ✓Keep it concise
- ✓Show enthusiasm
- ✓Tailor it to the role
- ✓Mention measurable results
Don'ts
- ✗Recite your entire resume
- ✗Ramble without structure
- ✗Get too personal
- ✗Sound rehearsed or robotic
Tips
- →Research the company's mission, products, and culture
- →Connect their goals to your career aspirations
- →Be specific — generic answers stand out negatively
- →Mention something you genuinely admire
Do's
- ✓Show you've done research
- ✓Connect your skills to their needs
- ✓Be genuine
- ✓Mention specific products or initiatives
Don'ts
- ✗Say 'I just need a job'
- ✗Focus only on salary or benefits
- ✗Give a generic answer
- ✗Criticize their current product
Tips
- →Show ambition but stay realistic
- →Align your goals with the company's trajectory
- →Mention both short-term and long-term goals
- →Emphasize growth, not just titles
Do's
- ✓Show ambition
- ✓Align with the role
- ✓Mention learning goals
- ✓Be specific about timeframes
Don'ts
- ✗Say 'I want your job'
- ✗Focus only on money or title
- ✗Have no clear direction
- ✗Sound like you'll leave quickly
Behavioral
10 questionsTips
- →Use the STAR method: Situation → Task → Action → Result
- →Choose a real challenge with a positive outcome
- →Focus on YOUR actions, not the team's
- →Quantify the result whenever possible
Do's
- ✓Pick a meaningful challenge
- ✓Show problem-solving process
- ✓Quantify results
- ✓Reflect on what you learned
Don'ts
- ✗Blame others
- ✗Choose a trivial problem
- ✗Skip the resolution
- ✗Exaggerate your role
Tips
- →Highlight collaboration, not just your individual contribution
- →Show how you communicated and resolved conflicts
- →Demonstrate adaptability to different working styles
- →Mention the team's achievement, not just yours
Do's
- ✓Show collaboration skills
- ✓Mention communication
- ✓Highlight conflict resolution
- ✓Credit the team
Don'ts
- ✗Take all the credit
- ✗Ignore team dynamics
- ✗Skip the outcome
- ✗Badmouth teammates
Tips
- →Give a specific example with a deadline or high-stakes situation
- →Show your coping mechanisms (prioritization, breaking tasks down)
- →Demonstrate that pressure makes you focused, not panicked
- →Mention how you maintain quality under pressure
Do's
- ✓Provide a concrete example
- ✓Show systematic thinking
- ✓Mention communication under pressure
- ✓Highlight maintaining quality
Don'ts
- ✗Say 'I don't feel pressure'
- ✗Sound overwhelmed
- ✗Blame the situation
- ✗Forget to mention the outcome
Tips
- →Choose a genuine failure, not a disguised success
- →Take full ownership — no excuses
- →Focus on what you learned and how you changed
- →Show growth since the failure
Do's
- ✓Be honest about the failure
- ✓Take responsibility
- ✓Show concrete lessons learned
- ✓Demonstrate growth
Don'ts
- ✗Blame others or circumstances
- ✗Choose a trivial failure
- ✗Skip the learning
- ✗Sound like you haven't grown
Tips
- →Leadership isn't about titles — show initiative
- →Describe how you motivated or guided others
- →Show decision-making under uncertainty
- →Highlight the impact of your leadership
Do's
- ✓Show initiative
- ✓Demonstrate influence without authority
- ✓Mention mentoring
- ✓Quantify the impact
Don'ts
- ✗Confuse leadership with bossing people around
- ✗Only talk about yourself
- ✗Forget to mention the team's response
- ✗Exaggerate your role
Tips
- →Show a systematic approach (Eisenhower matrix, impact/effort)
- →Give an example of competing priorities
- →Mention communication with stakeholders
- →Show flexibility when priorities change
Do's
- ✓Show a clear system
- ✓Mention stakeholder communication
- ✓Demonstrate flexibility
- ✓Give a real example
Don'ts
- ✗Say 'I just do what's most urgent'
- ✗Ignore stakeholder input
- ✗Sound rigid
- ✗Forget to mention outcomes
Tips
- →Show respect for differing opinions
- →Focus on finding the best solution, not winning
- →Highlight how you communicated your perspective
- →Show the resolution and what you learned
Do's
- ✓Show mutual respect
- ✓Focus on data and evidence
- ✓Highlight compromise or resolution
- ✓Show you can disagree constructively
Don'ts
- ✗Make it personal
- ✗Say you always agree
- ✗Badmouth the colleague
- ✗Forget to resolve the disagreement
Tips
- →Choose something that exceeded your normal responsibilities
- →Show initiative without being asked
- →Quantify the impact on the team or company
- →Demonstrate that you care about the bigger picture
Do's
- ✓Show initiative
- ✓Quantify the impact
- ✓Demonstrate ownership
- ✓Show it benefited others
Don'ts
- ✗Brag without substance
- ✗Choose a trivial example
- ✗Forget the outcome
- ✗Sound like you were asked to do it
Tips
- →Show you actively seek feedback, not just receive it
- →Give an example of acting on feedback
- →Demonstrate emotional maturity
- →Show how feedback made you better
Do's
- ✓Show you seek feedback proactively
- ✓Give a concrete example
- ✓Demonstrate acting on feedback
- ✓Show growth
Don'ts
- ✗Say 'I never get negative feedback'
- ✗Sound defensive
- ✗Ignore the feedback
- ✗Badmouth the person who gave it
Tips
- →Show flexibility and a positive attitude
- →Describe how you learned something new quickly
- →Highlight the outcome despite the disruption
- →Show you embrace change rather than resist it
Do's
- ✓Show a positive attitude toward change
- ✓Mention rapid learning
- ✓Quantify the outcome
- ✓Demonstrate adaptability
Don'ts
- ✗Complain about the change
- ✗Say you prefer things stay the same
- ✗Skip the learning curve
- ✗Forget the result
Technical HR
4 questionsTips
- →Show genuine passion, not just interest in salary
- →Connect to impact — how technology changes lives
- →Mention specific areas that excite you
- →Show you understand the industry's challenges
Do's
- ✓Show genuine passion
- ✓Connect to real-world impact
- ✓Mention specific technologies
- ✓Show awareness of industry trends
Don'ts
- ✗Say 'the pay is good'
- ✗Give a generic answer
- ✗Sound like you fell into it
- ✗Ignore the bigger picture
Tips
- →Mention specific sources (blogs, podcasts, communities)
- →Show you practice, not just read
- →Mention contributing to open source or side projects
- →Demonstrate a learning routine
Do's
- ✓Name specific resources
- ✓Show active learning
- ✓Mention practice over theory
- ✓Demonstrate consistency
Don'ts
- ✗Say 'I just Google things'
- ✗Be vague about sources
- ✗Sound like you only learn at work
- ✗Ignore hands-on practice
Tips
- →Choose a project with real impact or technical depth
- →Explain the problem, your approach, and the result
- →Show technical decision-making and tradeoffs
- →Mention what you'd do differently now
Do's
- ✓Show technical depth
- ✓Explain tradeoffs
- ✓Quantify impact
- ✓Show self-reflection
Don'ts
- ✗Choose a trivial project
- ✗Only talk about the tech stack
- ✗Forget to mention impact
- ✗Sound like you followed a tutorial
Tips
- →Show a systematic methodology
- →Mention tools you use (logging, breakpoints, profilers)
- →Emphasize reproducing the bug first
- →Show patience and methodical thinking
Do's
- ✓Show a systematic process
- ✓Mention specific tools
- ✓Emphasize reproduction first
- ✓Show patience
Don'ts
- ✗Say 'I just keep trying things'
- ✗Skip the methodology
- ✗Forget about regression testing
- ✗Sound frustrated by debugging
Closing
3 questionsTips
- →Always have at least 3 questions prepared
- →Ask about team culture, growth, and technical challenges
- →Show genuine curiosity about the role
- →Avoid asking about salary or benefits at this stage
Do's
- ✓Ask thoughtful questions
- ✓Show curiosity about growth
- ✓Ask about challenges
- ✓Demonstrate you've researched
Don'ts
- ✗Say 'No, I'm good'
- ✗Ask about salary too early
- ✗Ask things easily found on the website
- ✗Ask about vacation policy
Tips
- →Summarize your key strengths concisely
- →Connect your skills directly to their needs
- →Show enthusiasm for the role and company
- →Mention what sets you apart from other candidates
Do's
- ✓Be confident but not arrogant
- ✓Connect skills to their needs
- ✓Show enthusiasm
- ✓Mention unique value
Don'ts
- ✗Be modest to the point of weakness
- ✗Give a generic answer
- ✗Forget to mention the company
- ✗Sound desperate
Tips
- →Research market rates on Glassdoor, Levels.fyi, and Payscale
- →Give a range, not a fixed number
- →Base it on total compensation (base + bonus + equity)
- →Show flexibility and willingness to negotiate
Do's
- ✓Do your research first
- ✓Give a range
- ✓Mention total compensation
- ✓Show flexibility
Don'ts
- ✗Give a specific number without context
- ✗Say 'I'll take anything'
- ✗Focus only on money
- ✗Lowball yourself
Coding Questions
175python
30 problemsProblem
Write a function that reverses a given string.
Input
hello
Output
olleh
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Forgetting that strings are immutable in Python
- ⚠Using slicing incorrectly with wrong step value
- ⚠Not handling empty strings
Problem
Check if a given string reads the same forwards and backwards.
Input
racecar
Output
True
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Not normalizing case before comparison
- ⚠Including spaces in the comparison
- ⚠Using extra space unnecessarily instead of two-pointer approach
Problem
Compute the factorial of a non-negative integer n.
Input
5
Output
120
Complexity
O(n) time, O(n) space (recursive stack)
Common Mistakes
- ⚠Not handling negative input
- ⚠Off-by-one error in base case
- ⚠Stack overflow for very large inputs without iterative approach
Problem
Return the nth Fibonacci number (0-indexed).
Input
7
Output
13
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Using naive recursion without memoization leading to O(2^n)
- ⚠Off-by-one errors in indexing
- ⚠Not handling n=0 and n=1 base cases
Problem
Check if a given integer is a prime number.
Input
17
Output
True
Complexity
O(sqrt(n)) time, O(1) space
Common Mistakes
- ⚠Not handling n < 2 correctly
- ⚠Checking divisibility up to n instead of sqrt(n)
- ⚠Including 1 as a prime number
Problem
Find the maximum element in an array of integers.
Input
[3, 1, 4, 1, 5, 9, 2, 6]
Output
9
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Not handling empty arrays
- ⚠Initializing max to 0 instead of the first element
- ⚠Using max() built-in without understanding the algorithm
Problem
Remove duplicate elements from a list while preserving order.
Input
[1, 2, 2, 3, 4, 4, 5]
Output
[1, 2, 3, 4, 5]
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Using set() which does not preserve order
- ⚠Not using a set for O(1) lookups resulting in O(n^2)
- ⚠Modifying the list while iterating over it
Problem
Given an array and a target, return indices of two numbers that add up to the target.
Input
[2, 7, 11, 15], target = 9
Output
[0, 1]
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Using brute force O(n^2) approach instead of hash map
- ⚠Returning values instead of indices
- ⚠Not handling the case where no solution exists
Problem
Merge two sorted arrays into a single sorted array.
Input
[1, 3, 5], [2, 4, 6]
Output
[1, 2, 3, 4, 5, 6]
Complexity
O(n + m) time, O(n + m) space
Common Mistakes
- ⚠Using sort() after concatenation instead of two-pointer merge
- ⚠Forgetting to extend with remaining elements
- ⚠Off-by-one errors with pointer increments
Problem
Implement binary search on a sorted array to find the index of a target value.
Input
[1, 2, 3, 4, 5, 6, 7], target = 5
Output
4
Complexity
O(log n) time, O(1) space
Common Mistakes
- ⚠Using (left + right) // 2 which can overflow in other languages
- ⚠Using <= vs < inconsistently in the loop condition
- ⚠Not updating left and right correctly leading to infinite loops
Problem
Implement the bubble sort algorithm to sort an array of integers.
Input
[64, 34, 25, 12, 22, 11, 90]
Output
[11, 12, 22, 25, 34, 64, 90]
Complexity
O(n^2) time, O(1) space
Common Mistakes
- ⚠Not optimizing with the swapped flag
- ⚠Iterating to n instead of n-i-1 in inner loop
- ⚠Not returning the sorted array
Problem
Implement the quicksort algorithm using Lomuto partition scheme.
Input
[10, 7, 8, 9, 1, 5]
Output
[1, 5, 7, 8, 9, 10]
Complexity
O(n log n) average, O(n^2) worst, O(log n) space
Common Mistakes
- ⚠Not handling already sorted arrays (worst case O(n^2))
- ⚠Using the first element as pivot without randomization
- ⚠Modifying the list in-place incorrectly
Problem
Implement the merge sort algorithm recursively.
Input
[38, 27, 43, 3, 9, 82, 10]
Output
[3, 9, 10, 27, 38, 43, 82]
Complexity
O(n log n) time, O(n) space
Common Mistakes
- ⚠Slicing with wrong indices in the recursive calls
- ⚠Not handling the base case of single-element arrays
- ⚠Using <= instead of < in comparison causing instability
Problem
Reverse a singly linked list iteratively.
Input
1 -> 2 -> 3 -> 4 -> 5
Output
5 -> 4 -> 3 -> 2 -> 1
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Losing the reference to the next node before reassigning
- ⚠Not handling empty list or single node cases
- ⚠Returning the original head instead of the new head (prev)
Problem
Implement a stack data structure with push, pop, peek, and is_empty operations.
Input
push(1), push(2), peek(), pop(), is_empty()
Output
2, 2, False
Complexity
O(1) for all operations
Common Mistakes
- ⚠Not checking for empty stack before pop/peek
- ⚠Using insert(0, item) instead of append for push
- ⚠Returning index instead of value on pop
Problem
Implement a queue with enqueue, dequeue, peek, and is_empty operations.
Input
enqueue(1), enqueue(2), dequeue(), peek(), enqueue(3), dequeue()
Output
1, 2, 3
Complexity
O(1) enqueue, O(n) dequeue (list-based)
Common Mistakes
- ⚠Using pop() instead of pop(0) for dequeue
- ⚠Not raising exception for dequeue on empty queue
- ⚠Forgetting that list.pop(0) is O(n)
Problem
Implement in-order, pre-order, and post-order traversals of a binary tree.
Input
Tree: 1(root)->2(left),3(right), 2->4(left),2->5(right)
Output
In-order: [4,2,5,1,3], Pre-order: [1,2,4,5,3], Post-order: [4,5,2,3,1]
Complexity
O(n) time, O(h) space where h is height
Common Mistakes
- ⚠Mixing up in-order and pre-order sequences
- ⚠Forgetting the base case for null nodes
- ⚠Using append incorrectly in iterative approaches
Problem
Implement BFS and DFS traversal for a graph represented as an adjacency list.
Input
Graph: {0:[1,2], 1:[2], 2:[3], 3:[]}, start: 0Output
BFS: [0, 1, 2, 3], DFS: [0, 1, 2, 3]
Complexity
O(V + E) time, O(V) space
Common Mistakes
- ⚠Forgetting to mark nodes as visited causing infinite loops
- ⚠Using a list instead of a set for visited nodes
- ⚠Not handling disconnected components
Problem
Compute the nth Fibonacci number using dynamic programming (bottom-up).
Input
10
Output
55
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Using recursion without memoization (exponential time)
- ⚠Index out of bounds for base cases
- ⚠Not optimizing space by only keeping last two values
Problem
Find the length of the longest substring without repeating characters.
Input
abcabcbb
Output
3
Complexity
O(n) time, O(min(n, m)) space where m is charset size
Common Mistakes
- ⚠Using a set and sliding window without tracking exact positions
- ⚠Resetting start to 0 instead of the position after the duplicate
- ⚠Not updating the character index map correctly
Problem
Check if a string of brackets is valid (properly opened and closed).
Input
()[]{}Output
True
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Not handling the case of an empty stack when popping
- ⚠Using only one pair of brackets in the mapping
- ⚠Forgetting to check if the stack is empty at the end
Problem
Given an array containing n distinct numbers from 0 to n, find the missing number.
Input
[3, 0, 1]
Output
2
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Using sort() which is O(n log n) instead of math formula
- ⚠Integer overflow in other languages with sum formula
- ⚠Not handling edge case where 0 or n is missing
Problem
Move all zeros to the end while maintaining relative order of non-zero elements.
Input
[0, 1, 0, 3, 12]
Output
[1, 3, 12, 0, 0]
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Using a new array instead of in-place manipulation
- ⚠Not preserving relative order of non-zero elements
- ⚠Using pop and append which is O(n^2)
Problem
Find the intersection of two arrays (elements present in both).
Input
[1, 2, 2, 1], [2, 2]
Output
[2]
Complexity
O(n + m) time, O(min(n, m)) space
Common Mistakes
- ⚠Not handling duplicates correctly
- ⚠Using nested loops O(n*m) instead of set intersection
- ⚠Modifying the original arrays
Problem
Find all elements that appear twice in an array where elements are in range [1, n].
Input
[4, 3, 2, 7, 8, 2, 3, 1]
Output
[2, 3]
Complexity
O(n) time, O(1) extra space
Common Mistakes
- ⚠Using a hash map which uses O(n) extra space
- ⚠Not using absolute value when indexing after negation
- ⚠Modifying the array without restoring it
Problem
Create a decorator that logs the execution time of a function.
Input
Call a function decorated with @timer
Output
Function executed in X.XXX seconds
Complexity
O(1) overhead, depends on wrapped function
Common Mistakes
- ⚠Not using @wraps which loses original function metadata
- ⚠Forgetting to return the result of the wrapped function
- ⚠Not using *args and **kwargs making decorator non-general
Problem
Safely convert a list of strings to integers with proper exception handling.
Input
["1", "2", "abc", "4"]
Output
[1, 2, None, 4]
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Catching broad Exception instead of specific ValueError
- ⚠Using a single try/except for the entire loop instead of per item
- ⚠Not preserving partial results on failure
Problem
Write text to a file and read it back with proper file handling.
Input
Write Hello World to file, then read it
Output
Hello World
Complexity
O(n) time where n is file size
Common Mistakes
- ⚠Not using with statement leading to resource leaks
- ⚠Not handling FileNotFoundError or PermissionError
- ⚠Forgetting to close the file explicitly without context manager
Problem
Use list comprehensions to extract squares of even numbers from a list.
Input
[1, 2, 3, 4, 5, 6, 7, 8]
Output
[4, 16, 36, 64]
Complexity
O(n) time, O(k) space where k is number of even elements
Common Mistakes
- ⚠Using map and filter instead of idiomatic list comprehension
- ⚠Placing the filter condition before the transformation
- ⚠Using multiple list comprehensions instead of one combined expression
Problem
Implement a generator that yields Fibonacci numbers lazily.
Input
10
Output
First 10 Fibonacci numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
Complexity
O(1) per yield, O(n) to collect n values
Common Mistakes
- ⚠Using return instead of yield creating a regular function
- ⚠Not using yield from for delegating generators
- ⚠Consuming the generator multiple times (generators are single-use)
c
20 problemsProblem
Reverse a C string in place.
Input
hello
Output
olleh
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠String literals are read-only must use char array
- ⚠Off-by-one in the swap index calculation
- ⚠Using strlen without including string.h
Problem
Check if a string is a palindrome in C.
Input
racecar
Output
1 (true)
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Calculating right as strlen() without subtracting 1
- ⚠Not handling empty strings
- ⚠Comparing signed and unsigned values
Problem
Compute the factorial of a number using recursion.
Input
5
Output
120
Complexity
O(n) time, O(n) space (recursive stack)
Common Mistakes
- ⚠Using int instead of long long causing overflow
- ⚠Not handling negative input
- ⚠Missing base case leading to infinite recursion
Problem
Print the first n Fibonacci numbers.
Input
8
Output
0 1 1 2 3 5 8 13
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Using recursion without memoization (O(2^n))
- ⚠Integer overflow for large n
- ⚠Printing n+1 or n-1 numbers
Problem
Check if a number is prime in C.
Input
17
Output
1 (true)
Complexity
O(sqrt(n)) time, O(1) space
Common Mistakes
- ⚠Including math.h for sqrt() and forgetting -lm flag
- ⚠Checking up to n instead of sqrt(n)
- ⚠Not handling n < 2
Problem
Reverse an integer array in place.
Input
[1, 2, 3, 4, 5]
Output
[5, 4, 3, 2, 1]
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Losing array size when passing to function
- ⚠Using sizeof inside the function which gives pointer size
- ⚠Iterating to size instead of size/2
Problem
Multiply two NxN matrices.
Input
A=[[1,2],[3,4]], B=[[5,6],[7,8]]
Output
[[19,22],[43,50]]
Complexity
O(N^3) time, O(N^2) space
Common Mistakes
- ⚠Forgetting to initialize C[i][j] to 0
- ⚠Wrong loop nesting order causing incorrect multiplication
- ⚠Using VLA which may not be supported
Problem
Implement a singly linked list with insert, delete, and display.
Input
Insert 1,2,3 then delete 2
Output
1 3
Complexity
O(n) for delete and search, O(1) for insert at head
Common Mistakes
- ⚠Memory leaks by not freeing deleted nodes
- ⚠Dereferencing NULL pointer when list is empty
- ⚠Not using double pointer (**head) for modifications
Problem
Implement a stack using an array.
Input
Push 10, 20, 30 then pop
Output
30
Complexity
O(1) for push and pop
Common Mistakes
- ⚠Not checking for stack overflow/underflow
- ⚠Using post-increment instead of pre-increment incorrectly
- ⚠Global variables causing issues with multiple stacks
Problem
Implement a circular queue using an array.
Input
Enqueue 1,2,3 then dequeue twice
Output
1 2
Complexity
O(1) for enqueue and dequeue
Common Mistakes
- ⚠Not implementing circular logic with modulo
- ⚠Not handling the case when queue becomes empty
- ⚠Confusing full condition with empty condition
Problem
Implement in-order traversal of a binary tree.
Input
Tree: 1->2(left),3(right), 2->4(left),5(right)
Output
4 2 5 1 3
Complexity
O(n) time, O(h) space
Common Mistakes
- ⚠Not checking for NULL before dereferencing
- ⚠Memory leaks from not freeing tree nodes
- ⚠Incorrect pointer assignment for child nodes
Problem
Sort an integer array using bubble sort.
Input
[64, 34, 25, 12, 22, 11, 90]
Output
[11, 12, 22, 25, 34, 64, 90]
Complexity
O(n^2) time, O(1) space
Common Mistakes
- ⚠Inner loop going to n instead of n-i-1
- ⚠Not passing array size to the function
- ⚠Integer overflow when swapping large values
Problem
Sort an integer array using selection sort.
Input
[29, 10, 14, 37, 13]
Output
[10, 13, 14, 29, 37]
Complexity
O(n^2) time, O(1) space
Common Mistakes
- ⚠Not finding the actual minimum in the unsorted portion
- ⚠Swapping unconditionally instead of checking min_idx != i
- ⚠Using wrong loop bounds
Problem
Sort an integer array using insertion sort.
Input
[12, 11, 13, 5, 6]
Output
[5, 6, 11, 12, 13]
Complexity
O(n^2) time, O(1) space
Common Mistakes
- ⚠Not saving arr[i] before shifting elements
- ⚠Shifting in wrong direction
- ⚠Off-by-one in inner loop
Problem
Implement merge sort for an integer array.
Input
[38, 27, 43, 3, 9, 82, 10]
Output
[3, 9, 10, 27, 38, 43, 82]
Complexity
O(n log n) time, O(n) space
Common Mistakes
- ⚠Memory leak by not freeing temporary arrays
- ⚠Integer overflow in midpoint calculation
- ⚠Off-by-one in merge indices
Problem
Implement quick sort using the last element as pivot.
Input
[10, 7, 8, 9, 1, 5]
Output
[1, 5, 7, 8, 9, 10]
Complexity
O(n log n) average, O(n^2) worst, O(log n) space
Common Mistakes
- ⚠Stack overflow on already sorted arrays
- ⚠Off-by-one in partition boundaries
- ⚠Not using median-of-three pivot selection
Problem
Implement iterative binary search on a sorted array.
Input
[2, 3, 4, 10, 40], target = 10
Output
3
Complexity
O(log n) time, O(1) space
Common Mistakes
- ⚠Using (left + right) / 2 which can overflow
- ⚠Using >= instead of > for mid comparison
- ⚠Not handling the case when element is not found
Problem
Implement character counting and substring extraction without string.h.
Input
Count 'l' in 'hello world'
Output
3
Complexity
O(n) time, O(1) or O(m) space for substring
Common Mistakes
- ⚠Forgetting null terminator in substring
- ⚠Dereferencing past end of string
- ⚠Using string.h functions when not allowed
Problem
Dynamically allocate, resize, and free memory for an integer array.
Input
Allocate for 5 elements, resize to 10, free
Output
Memory operations complete
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Not checking malloc/realloc return value for NULL
- ⚠Assigning realloc result directly to original pointer
- ⚠Accessing memory after free()
Problem
Write data to a file and read it back line by line.
Input
Write Hello World to file, read it back
Output
Hello World
Complexity
O(n) time, O(1) extra space
Common Mistakes
- ⚠Not checking if fopen() returns NULL
- ⚠Not closing the file with fclose()
- ⚠Using gets() instead of fgets() (buffer overflow)
cpp
25 problemsProblem
Reverse a string using C++ standard library.
Input
hello
Output
olleh
Complexity
O(n) time, O(n) space (for copy)
Common Mistakes
- ⚠Modifying the original string when only a copy should be reversed
- ⚠Using str.length() - 1 as index without checking empty string
- ⚠Mixing up begin() and end() iterators
Problem
Check if a string is a palindrome using two pointers.
Input
racecar
Output
true
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Using string reversal instead of two-pointer approach
- ⚠Not using const reference causing unnecessary copy
- ⚠Signed/unsigned comparison warning with size_t
Problem
Compute factorial using recursion.
Input
10
Output
3628800
Complexity
O(n) time, O(n) space (recursive)
Common Mistakes
- ⚠Using int instead of long long causing overflow
- ⚠Stack overflow for large n with recursion
- ⚠Not handling negative input
Problem
Compute Fibonacci using dynamic programming with memoization.
Input
10
Output
55
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Not initializing memo vector to -1
- ⚠Using naive recursion without memoization
- ⚠Integer overflow for large n
Problem
Check if a number is prime using 6k+/-1 optimization.
Input
29
Output
true
Complexity
O(sqrt(n)) time, O(1) space
Common Mistakes
- ⚠Forgetting to include cmath for sqrt()
- ⚠Not handling n=2 and n=3 correctly
- ⚠Using i*i <= n which may overflow for large n
Problem
Demonstrate std::vector operations: insert, erase, find, and sort.
Input
Insert {5,3,1,4,2}, sort, erase element at index 2Output
1 2 4 5
Complexity
O(n log n) for sort, O(n) for find/erase
Common Mistakes
- ⚠Using index-based access after erase (iterators invalidated)
- ⚠Not checking if find() returned end() before erasing
- ⚠Mixing push_back and emplace_back incorrectly
Problem
Reverse a singly linked list using pointers.
Input
1 -> 2 -> 3 -> 4 -> 5
Output
5 -> 4 -> 3 -> 2 -> 1
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Memory leaks from not deleting nodes
- ⚠Losing the next pointer before reassigning
- ⚠Returning the original head instead of new head
Problem
Implement a min-stack that tracks minimum element.
Input
push(3), push(1), push(5), getMin(), pop(), getMin()
Output
1, 3
Complexity
O(1) for all operations
Common Mistakes
- ⚠Not using <= in min_stack push (misses equal minimums)
- ⚠Forgetting to pop from min_stack when top elements match
- ⚠Not checking for empty stack before accessing top()
Problem
Implement a queue using two stacks.
Input
enqueue(1), enqueue(2), dequeue(), enqueue(3), dequeue()
Output
1, 3
Complexity
O(1) amortized for enqueue/dequeue
Common Mistakes
- ⚠Transferring when s2 still has elements
- ⚠Not handling empty queue dequeue
- ⚠Making transfer O(n) every time instead of amortized
Problem
Implement BST with insert, search, and in-order traversal.
Input
Insert 5,3,7,1,4,6,8 then search 4
Output
1 3 4 5 6 7 8, Found: true
Complexity
O(h) for insert/search, O(n) for traversal
Common Mistakes
- ⚠Not returning the modified root in recursive insert
- ⚠Memory leaks from not deleting nodes
- ⚠Forgetting to handle duplicate values
Problem
Implement a self-balancing AVL tree with rotations.
Input
Insert 10, 20, 30, 40, 50, 25
Output
Balanced tree with proper rotations applied
Complexity
O(log n) for insert, search, delete
Common Mistakes
- ⚠Not updating height after rotation
- ⚠Wrong rotation cases (LR, RL vs LL, RR)
- ⚠Not returning the new root after rotation
Problem
Implement BFS traversal on a graph using adjacency list.
Input
Graph: 0->[1,2], 1->[2], 2->[3], 3->[4]
Output
0 1 2 3 4
Complexity
O(V + E) time, O(V) space
Common Mistakes
- ⚠Not marking nodes as visited before pushing to queue
- ⚠Using DFS (stack) instead of BFS (queue)
- ⚠Not using const reference for adjacency list
Problem
Implement DFS traversal iteratively using a stack.
Input
Graph: 0->[1,2], 1->[2], 2->[0,3], 3->[3]
Output
0 1 2 3
Complexity
O(V + E) time, O(V) space
Common Mistakes
- ⚠Pushing children in wrong order
- ⚠Not checking visited after pop
- ⚠Using recursion that may stack overflow for large graphs
Problem
Find shortest paths from source to all vertices in a weighted graph.
Input
4 nodes, edges: 0->1(1), 0->2(4), 1->2(2), 1->3(6), 2->3(3)
Output
0:0, 1:1, 2:3, 3:6
Complexity
O((V + E) log V) with priority queue
Common Mistakes
- ⚠Not skipping stale entries in priority queue
- ⚠Using max-heap instead of min-heap
- ⚠Not initializing distances to INT_MAX
Problem
Find all-pairs shortest paths using Floyd-Warshall.
Input
4 nodes with weighted edges
Output
4x4 distance matrix with shortest paths
Complexity
O(V^3) time, O(V^2) space
Common Mistakes
- ⚠Overflow when adding two INT_MAX values
- ⚠Wrong loop order (k must be outermost)
- ⚠Not checking for INT_MAX before addition
Problem
Sort an array using bubble sort with early termination.
Input
[5, 1, 4, 2, 8]
Output
[1, 2, 4, 5, 8]
Complexity
O(n^2) time, O(1) space
Common Mistakes
- ⚠Using vector size incorrectly after modifications
- ⚠Not using std::swap or manual swap with temp variable
- ⚠Forgetting early termination optimization
Problem
Implement quicksort with Lomuto partition scheme.
Input
[3, 6, 8, 10, 1, 2, 1]
Output
[1, 1, 2, 3, 6, 8, 10]
Complexity
O(n log n) average, O(n^2) worst
Common Mistakes
- ⚠Using arr.size() - 1 which is unsigned and can wrap around
- ⚠Off-by-one in partition loop boundary
- ⚠Stack overflow on sorted arrays
Problem
Implement merge sort using std::vector.
Input
[12, 11, 13, 5, 6, 7]
Output
[5, 6, 7, 11, 12, 13]
Complexity
O(n log n) time, O(n) space
Common Mistakes
- ⚠Signed/unsigned comparison warnings with .size()
- ⚠Wrong mid calculation causing infinite recursion
- ⚠Not copying remaining elements correctly
Problem
Implement lower_bound and upper_bound binary search.
Input
[1, 2, 2, 2, 3, 4], target = 2
Output
lower_bound: 1, upper_bound: 4
Complexity
O(log n) time, O(1) space
Common Mistakes
- ⚠Confusing lower_bound with upper_bound conditions
- ⚠Using lo <= hi instead of lo < hi causing infinite loop
- ⚠Not using lo + (hi - lo) / 2 to avoid overflow
Problem
Use std::sort, std::find, std::count_if, std::accumulate, and std::transform.
Input
[5, 3, 1, 4, 2]
Output
Sorted, found 3 at index 1, count>2: 3, sum: 15, doubled: [2,4,6,8,10]
Complexity
Depends on algorithm used
Common Mistakes
- ⚠Using wrong iterator ranges
- ⚠Not initializing accumulate with a starting value
- ⚠Lambda capture issues
Problem
Write a template function for binary search and a template class for a generic pair.
Input
Search for 5 in [1,3,5,7,9], Pair<string,int>("age", 25)Output
Found at index 2, Pair: age=25
Complexity
O(log n) for binary search
Common Mistakes
- ⚠Not using const reference in template parameters
- ⚠Forgetting that templates must be defined in headers
- ⚠Not supporting operator< for custom types
Problem
Use std::unique_ptr and std::shared_ptr for automatic memory management.
Input
Create unique_ptr to int, shared_ptr to string
Output
Automatic cleanup demonstrated
Complexity
O(1) for creation and destruction
Common Mistakes
- ⚠Using new/delete with smart pointers (use make_unique/make_shared)
- ⚠Creating circular references with shared_ptr (use weak_ptr)
- ⚠Copying unique_ptr instead of moving
Problem
Use lambda expressions with STL algorithms.
Input
[3,1,4,1,5,9,2,6]
Output
Sorted: 1 1 2 3 4 5 6 9, Even count: 3, Filtered: 4 6
Complexity
Depends on algorithm
Common Mistakes
- ⚠Not capturing variables by reference when modifying them
- ⚠Using [=] capture when [&] is needed for performance
- ⚠Forgetting explicit return type for complex lambdas
Problem
Read and write files using std::fstream, std::ifstream, and std::ofstream.
Input
Write lines to file, read them back
Output
File contents printed line by line
Complexity
O(n) for reading/writing
Common Mistakes
- ⚠Not checking if file opened successfully
- ⚠Not closing file before reading (RAII helps)
- ⚠Using wrong file mode (binary vs text)
Problem
Implement custom exceptions and proper try-catch hierarchy.
Input
Divide 10 by 0, then throw custom exception
Output
Division by zero caught, Custom error caught
Complexity
O(1) for exception throwing and catching
Common Mistakes
- ⚠Throwing exceptions by value instead of by reference
- ⚠Catching derived exceptions before base class
- ⚠Using exceptions for normal control flow
html
20 problemsProblem
Create a properly structured HTML5 page with semantic elements.
Input
A page with header, nav, main, article, aside, footer
Output
Valid HTML5 document with semantic structure
Complexity
N/A - Structural markup
Common Mistakes
- ⚠Using div instead of semantic elements like header, main, footer
- ⚠Missing lang attribute on html element
- ⚠Not including viewport meta tag for responsive design
- ⚠Nesting header inside article when it should be page-level
Problem
Create a registration form with proper input types, labels, and validation.
Input
A form with name, email, password, confirm password
Output
Accessible form with client-side validation
Complexity
N/A - Form markup
Common Mistakes
- ⚠Not associating labels with inputs using for/id attributes
- ⚠Using placeholder as a substitute for labels
- ⚠Not using appropriate input types (email, date, etc.)
- ⚠Missing required attribute on mandatory fields
Problem
Create an accessible data table with thead, tbody, tfoot, and scope.
Input
A table showing employee data
Output
Accessible table with proper structure
Complexity
N/A - Table markup
Common Mistakes
- ⚠Missing caption element for table description
- ⚠Not using scope attribute for header cells
- ⚠Using layout tables instead of data tables
- ⚠Missing thead and tbody structure
Problem
Create ordered, unordered, and nested lists with proper nesting.
Input
A recipe with nested ingredient groups
Output
Properly structured nested lists
Complexity
N/A - List markup
Common Mistakes
- ⚠Nesting lists incorrectly (must be inside li element)
- ⚠Using br to separate list items instead of proper li
- ⚠Not using type attribute when specific numbering is needed
Problem
Create links with various attributes and responsive images with picture element.
Input
Navigation links and a responsive image
Output
Links with proper attributes and responsive images
Complexity
N/A - Link and image markup
Common Mistakes
- ⚠Missing alt attribute on images
- ⚠Not adding rel="noopener noreferrer" with target="_blank"
- ⚠Not specifying width and height on images (CLS issue)
- ⚠Using only srcset without a fallback src
Problem
Structure content with proper heading hierarchy and paragraph elements.
Input
A document with title, sections, and paragraphs
Output
Properly nested heading hierarchy (h1-h6)
Complexity
N/A - Text structure
Common Mistakes
- ⚠Skipping heading levels (h1 to h3)
- ⚠Using headings for styling instead of structure
- ⚠Not using semantic inline elements (strong, em, code)
- ⚠Multiple h1 elements on a single page
Problem
Replace generic divs with appropriate semantic tags for a blog post layout.
Input
Blog post with header, content, sidebar, and comments
Output
Semantically meaningful HTML structure
Complexity
N/A - Semantic structure
Common Mistakes
- ⚠Using div for everything instead of semantic tags
- ⚠Nesting section without headings
- ⚠Not using time element for dates
- ⚠Using b or i instead of strong and em
Problem
Create a modal dialog using the native dialog element with JavaScript.
Input
A button that opens a confirmation dialog
Output
Modal dialog that can be opened and closed
Complexity
N/A - Dialog interaction
Common Mistakes
- ⚠Using div-based modal instead of native dialog element
- ⚠Not using method="dialog" on the form inside dialog
- ⚠Forgetting to handle the close event for result
- ⚠Using show() instead of showModal()
Problem
Create an expandable FAQ section using details and summary elements.
Input
A FAQ with 3 expandable questions
Output
Native accordion without JavaScript
Complexity
N/A - Native accordion
Common Mistakes
- ⚠Not placing summary as the first child of details
- ⚠Using JavaScript for something that can be done natively
- ⚠Missing the open attribute for default-expanded sections
- ⚠Nesting details/summary incorrectly
Problem
Demonstrate localStorage and sessionStorage with a simple note saver.
Input
Save, retrieve, and delete notes from localStorage
Output
Persistent notes across page reloads
Complexity
N/A - Web Storage API
Common Mistakes
- ⚠Storing sensitive data in localStorage (not secure)
- ⚠Not handling QuotaExceededError when storage is full
- ⚠Confusing localStorage (persistent) with sessionStorage (tab-only)
- ⚠Storing objects without JSON.stringify/parse
Problem
Embed audio and video with multiple source formats and fallback content.
Input
A video player with poster image and audio player
Output
Media players with proper fallbacks
Complexity
N/A - Media embedding
Common Mistakes
- ⚠Not providing multiple source formats for cross-browser support
- ⚠Missing fallback content for browsers without media support
- ⚠Not adding type attribute to source elements
- ⚠Autoplaying media without user interaction
Problem
Use the canvas element to draw shapes and text with JavaScript.
Input
A canvas with rectangles, circles, lines, and text
Output
Visual shapes drawn on canvas
Complexity
N/A - Canvas 2D drawing
Common Mistakes
- ⚠Not checking if getContext() returns null
- ⚠Not setting width/height attributes (uses CSS defaults causing blur)
- ⚠Forgetting to beginPath() before drawing new shapes
- ⚠Missing aria-label for accessibility
Problem
Use custom data attributes to store and retrieve data via JavaScript.
Input
Cards with data attributes for user info
Output
JavaScript reads and displays data attributes
Complexity
N/A - Data attribute usage
Common Mistakes
- ⚠Using data attributes for CSS styling instead of classes
- ⚠Accessing data-user-id with dot notation instead of camelCase dataset.userId
- ⚠Storing large objects in data attributes
- ⚠Not following naming conventions (data-kebab-case)
Problem
Demonstrate the difference between block, inline, and inline-block elements.
Input
Mixed block and inline elements
Output
Visual demonstration of display behavior
Complexity
N/A - Display types
Common Mistakes
- ⚠Assuming inline elements respect width and height
- ⚠Using br for spacing instead of margin on block elements
- ⚠Not understanding that inline-block combines inline flow with block styling
- ⚠Confusing display:none with visibility:hidden
Problem
Add proper ARIA attributes to make a custom tab widget accessible.
Input
A tabbed interface with 3 tabs and panels
Output
Accessible tabs with roles, states, and keyboard navigation
Complexity
N/A - ARIA implementation
Common Mistakes
- ⚠Using ARIA roles on native HTML elements that already have them
- ⚠Not updating aria-selected state when switching tabs
- ⚠Missing keyboard navigation support
- ⚠Using aria-hidden incorrectly on focusable elements
Problem
Use the template element for client-side rendering of dynamic content.
Input
A list of users to render from data
Output
Dynamically rendered user cards from template
Complexity
N/A - Template usage
Common Mistakes
- ⚠Modifying template.content directly instead of cloning
- ⚠Not using cloneNode(true) for deep copy
- ⚠Querying the template instead of the clone
- ⚠Not using content property (must access .content)
Problem
Add comprehensive meta tags for SEO, social sharing, and browser behavior.
Input
A page needing proper meta configuration
Output
Complete meta tag setup
Complexity
N/A - Meta tag configuration
Common Mistakes
- ⚠Missing viewport meta tag for mobile
- ⚠Duplicate canonical URLs
- ⚠Missing Open Graph tags for social sharing
- ⚠Description too short or too long (150-160 chars ideal)
Problem
Implement client-side form validation using HTML5 constraint validation API.
Input
A contact form with required fields and patterns
Output
Form with real-time validation feedback
Complexity
N/A - Form validation
Common Mistakes
- ⚠Relying only on HTML5 validation without JavaScript fallback
- ⚠Not providing visual feedback for validation errors
- ⚠Using pattern without explaining the expected format
- ⚠Not handling the novalidate attribute correctly
Problem
Implement a skip navigation link for keyboard accessibility.
Input
A page with navigation and main content
Output
Skip link that becomes visible on focus
Complexity
N/A - Accessibility feature
Common Mistakes
- ⚠Skip link not visible when focused (defeats the purpose)
- ⚠Missing tabindex=-1 on the target element
- ⚠Skip link not the first focusable element
- ⚠Not using it with semantic landmarks
Problem
Use progress and meter elements to display dynamic values.
Input
A progress bar and a meter showing score
Output
Native progress and meter elements with JavaScript updates
Complexity
N/A - Native form elements
Common Mistakes
- ⚠Using div-based progress bars instead of native elements
- ⚠Not setting proper min/max values on meter
- ⚠Not understanding meter vs progress (indeterminate vs determinate)
- ⚠Missing fallback text inside the element
css
20 problemsProblem
Create a responsive navigation bar and card layout using CSS Flexbox.
Input
Nav with logo and links, and a row of cards
Output
Responsive flex layout with proper alignment
Complexity
N/A - Flexbox layout
Common Mistakes
- ⚠Not setting flex-wrap: wrap for responsive wrapping
- ⚠Using fixed widths instead of flex-basis
- ⚠Forgetting align-items vs align-content differences
- ⚠Not using gap property (still has poor support in older browsers)
Problem
Create a complex page layout with header, sidebar, main content, and footer using CSS Grid.
Input
A page with grid areas
Output
Responsive grid layout that adapts to screen size
Complexity
N/A - Grid layout
Common Mistakes
- ⚠Forgetting to set display: grid on the container
- ⚠Using px instead of fr units for flexible sizing
- ⚠Not understanding the difference between grid-template-rows and grid-auto-rows
- ⚠Not using minmax() for responsive grids
Problem
Demonstrate understanding of the CSS box model including margin collapsing and box-sizing.
Input
Elements with margins, padding, borders
Output
Properly styled boxes with box-sizing: border-box
Complexity
N/A - Box model concepts
Common Mistakes
- ⚠Not using box-sizing: border-box (default is content-box)
- ⚠Confusing padding (inside) with margin (outside)
- ⚠Not understanding margin collapsing
- ⚠Forgetting that percentage margin is based on parent width
Problem
Demonstrate static, relative, absolute, fixed, and sticky positioning.
Input
Elements needing various positioning contexts
Output
Elements positioned with different position values
Complexity
N/A - Positioning
Common Mistakes
- ⚠Using position: absolute without a positioned parent
- ⚠Not setting z-index for overlapping positioned elements
- ⚠Confusing fixed and sticky positioning
- ⚠Forgetting that absolute elements are removed from document flow
Problem
Create a fully responsive layout using media queries, fluid typography, and mobile-first approach.
Input
A page that works on mobile, tablet, and desktop
Output
Responsive layout adapting to different screen sizes
Complexity
N/A - Responsive design
Common Mistakes
- ⚠Using fixed widths without max-width
- ⚠Not using mobile-first approach
- ⚠Not testing on actual devices (only browser resizing)
- ⚠Using px for font sizes instead of rem/em/clamp()
Problem
Create keyframe animations and transitions for interactive elements.
Input
Elements needing hover effects, loading spinners, and entrance animations
Output
Smooth CSS animations and transitions
Complexity
N/A - CSS animations
Common Mistakes
- ⚠Using JavaScript for animations that can be done with CSS
- ⚠Not considering prefers-reduced-motion for accessibility
- ⚠Animating expensive properties (width, height) instead of transform/opacity
- ⚠Not using will-change for performance optimization
Problem
Use CSS custom properties for theming and dynamic values.
Input
A page with light/dark theme support
Output
Themeable design using CSS variables
Complexity
N/A - CSS custom properties
Common Mistakes
- ⚠Not defining fallback values with var(--name, fallback)
- ⚠Using CSS variables where a CSS preprocessor variable would suffice
- ⚠Forgetting that custom properties cascade and inherit
- ⚠Not scoping variables to the right element
Problem
Set up a typographic scale with proper line-height, letter-spacing, and font loading.
Input
Text content with headings, body, and code
Output
Well-structured typography system
Complexity
N/A - Typography
Common Mistakes
- ⚠Using px for font sizes instead of rem/em
- ⚠Not including web-safe fallback fonts
- ⚠Line-height below 1.2 for body text (hard to read)
- ⚠Not preloading critical fonts
Problem
Use modern CSS color functions including oklch, color-mix, and gradient techniques.
Input
Elements with various color and gradient backgrounds
Output
Modern CSS color usage
Complexity
N/A - CSS colors
Common Mistakes
- ⚠Using hex colors instead of modern oklch/hsl for better color spaces
- ⚠Not checking browser support for new color functions
- ⚠Overusing gradients causing performance issues
- ⚠Not considering color contrast for accessibility (WCAG)
Problem
Use ::before and ::after pseudo-elements for decorative and functional purposes.
Input
Elements needing decorative content, counters, and icons
Output
Enhanced elements with pseudo-element content
Complexity
N/A - Pseudo-elements
Common Mistakes
- ⚠Forgetting that content property is required for pseudo-elements to render
- ⚠Using pseudo-elements for content that should be in HTML (accessibility issue)
- ⚠Not setting display property on pseudo-elements (default is inline)
- ⚠Confusing ::before/::after with ::first-line/::first-letter
Problem
Use advanced CSS selectors including combinators, attribute selectors, and pseudo-classes.
Input
Complex DOM structures needing precise targeting
Output
Efficient CSS selectors without unnecessary specificity
Complexity
N/A - Advanced selectors
Common Mistakes
- ⚠Using !important instead of more specific selectors
- ⚠Over-relying on nth-child when classes would be simpler
- ⚠Not understanding specificity calculations
- ⚠Using :has() without checking browser support
Problem
Use native CSS nesting to write more maintainable stylesheets.
Input
Component styles with nested selectors
Output
Cleaner CSS using native nesting syntax
Complexity
N/A - CSS nesting
Common Mistakes
- ⚠Not checking browser support for native CSS nesting
- ⚠Over-nesting making selectors too specific
- ⚠Confusing & (nesting) with SASS/SCSS syntax differences
- ⚠Not using @layer for managing specificity
Problem
Implement CSS scroll snapping for a carousel or section-based layout.
Input
A horizontal carousel of cards
Output
Smooth scroll snapping behavior
Complexity
N/A - Scroll snap
Common Mistakes
- ⚠Using scroll-snap-type: mandatory causing jarring UX on long scrolls
- ⚠Not accounting for element height causing snap to middle
- ⚠Forgetting scroll-padding for fixed headers
- ⚠Not testing on touch devices
Problem
Use CSS clip-path to create creative shapes and reveal effects.
Input
Elements with custom shapes and hover reveal effects
Output
Elements clipped to various shapes
Complexity
N/A - clip-path
Common Mistakes
- ⚠clip-path clips content AND borders/box-shadows
- ⚠Not providing fallback for browsers without clip-path support
- ⚠Using complex clip-path polygon values that are hard to maintain
- ⚠Performance issues with animated clip-path on large elements
Problem
Use backdrop-filter for frosted glass effects and blur overlays.
Input
Overlays and navigation with glass-morphism effect
Output
Frosted glass UI elements
Complexity
N/A - backdrop-filter
Common Mistakes
- ⚠Not including -webkit-backdrop-filter for Safari
- ⚠Forgetting fallback for browsers without backdrop-filter support
- ⚠Using too much blur (performance impact on mobile)
- ⚠Not considering that backdrop-filter affects content behind element
Problem
Use container queries to create components that respond to their container size.
Input
A card component in different container sizes
Output
Cards that adapt layout based on parent container width
Complexity
N/A - Container queries
Common Mistakes
- ⚠Not setting container-type on the parent element
- ⚠Using container-type: size instead of inline-size (causes layout issues)
- ⚠Confusing container queries with media queries
- ⚠Not providing fallback for older browsers
Problem
Use CSS subgrid to align nested grid items across sibling containers.
Input
A row of cards with different content lengths
Output
Cards with perfectly aligned headers, bodies, and footers
Complexity
N/A - CSS subgrid
Common Mistakes
- ⚠Not providing fallback for browsers without subgrid support
- ⚠Using subgrid where simple flexbox would suffice
- ⚠Forgetting that subgrid only works in the grid axis direction
- ⚠Not understanding that parent must be a grid container
Problem
Use @layer to manage CSS specificity and organize stylesheet layers.
Input
A stylesheet with base, component, and utility layers
Output
Organized CSS with controlled specificity
Complexity
N/A - CSS @layer
Common Mistakes
- ⚠Not defining layer order upfront (order matters for specificity)
- ⚠Using @layer with third-party CSS that doesn't use layers
- ⚠Not understanding that unlayered styles always beat layered ones
- ⚠Overusing !important which defeats the purpose of layers
Problem
Use the :has() pseudo-class for parent selection based on children.
Input
Various parent-child relationship patterns
Output
CSS rules that target parents based on their children
Complexity
N/A - :has() selector
Common Mistakes
- ⚠Not checking browser support (Chromium 105+, Safari 15.4+)
- ⚠Using :has() for complex logic that should be in JavaScript
- ⚠Performance concerns with deeply nested :has() selectors
- ⚠Confusing :has() direction (it selects the parent, not the child)
Problem
Implement fluid responsive typography using clamp() and modern CSS functions.
Input
A page with various text elements
Output
Typography that scales smoothly between viewport sizes
Complexity
N/A - Fluid typography
Common Mistakes
- ⚠Using fixed pixel values for font sizes across breakpoints
- ⚠Not setting proper line-height for different heading sizes
- ⚠Line lengths exceeding 75 characters (hard to read)
- ⚠Not accounting for user font-size preferences
javascript
25 problemsProblem
Reverse a string using different JavaScript methods.
Input
hello
Output
olleh
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Using split('') on empty string producing ['']
- ⚠Forgetting to join the array back into a string
- ⚠Not handling unicode characters (emoji) correctly
Problem
Check if a string is a palindrome, ignoring case and non-alphanumeric characters.
Input
A man a plan a canal Panama
Output
true
Complexity
O(n) time, O(n) space for cleaned string
Common Mistakes
- ⚠Not normalizing to lowercase
- ⚠Including spaces and punctuation in comparison
- ⚠Using slice and reverse which creates unnecessary copies
Problem
Compute factorial using recursion and handle edge cases.
Input
5
Output
120
Complexity
O(n) time, O(n) stack space
Common Mistakes
- ⚠Not handling negative input
- ⚠Stack overflow for very large n
- ⚠Off-by-one in base case (n <= 1 vs n === 0)
Problem
Compute Fibonacci numbers using memoization to avoid redundant calculations.
Input
10
Output
55
Complexity
O(n) time with memoization, O(n) space
Common Mistakes
- ⚠Using naive recursion without memoization
- ⚠Not using Map/object for memo causing O(n) lookup
- ⚠Integer overflow for very large Fibonacci numbers
Problem
Demonstrate closures with practical examples: counter, private variables, and function factories.
Input
Various closure operations
Output
Encapsulated state demonstrations
Complexity
O(1) for each operation
Common Mistakes
- ⚠Confusing closures with lexical scope
- ⚠Closure holding reference to loop variable (classic var issue)
- ⚠Memory leaks from closures holding large objects
Problem
Implement a debounce function that delays function execution until after a pause.
Input
Rapid function calls
Output
Function executed only once after pause
Complexity
O(1) per call, O(delay) for execution
Common Mistakes
- ⚠Not preserving 'this' context with arrow functions
- ⚠Not using apply/call to pass arguments correctly
- ⚠Forgetting to clear the previous timeout
- ⚠Not implementing cancel and flush methods
Problem
Implement a throttle function that limits function execution to once per interval.
Input
Continuous rapid function calls
Output
Function executed at most once per interval
Complexity
O(1) per call
Common Mistakes
- ⚠Not handling trailing edge calls
- ⚠Using timestamp incorrectly for remaining time calculation
- ⚠Not clearing pending timeouts
- ⚠Throttle vs debounce confusion (throttle guarantees execution)
Problem
Implement a basic Promises/A+ compliant promise from scratch.
Input
Chained promise operations
Output
Working promise with then, catch, and chaining
Complexity
O(1) for promise creation and chaining
Common Mistakes
- ⚠Not handling synchronous executor errors
- ⚠Forgetting that then() returns a new promise
- ⚠Not implementing proper microtask scheduling
- ⚠Error in callback handler not caught properly
Problem
Use async/await with error handling, parallel execution, and sequential operations.
Input
Multiple asynchronous API calls
Output
Properly handled async operations with error handling
Complexity
O(n) for sequential, O(1) parallel (with limit)
Common Mistakes
- ⚠Using await in a loop when parallel execution is possible
- ⚠Not handling errors in async functions (unhandled rejection)
- ⚠Forgetting that async functions always return a Promise
- ⚠Not using AbortController for cancellable fetches
Problem
Create, modify, and delete DOM elements efficiently.
Input
A list that needs dynamic items added and removed
Output
Dynamic DOM updates without innerHTML
Complexity
O(n) for most operations
Common Mistakes
- ⚠Using innerHTML which is slow and XSS vulnerable
- ⚠Reflow issues from modifying DOM in a loop
- ⚠Not using DocumentFragment for batch insertions
- ⚠Forgetting to remove event listeners when removing elements
Problem
Implement event delegation to handle events on dynamically added elements.
Input
A list of items with dynamically added elements
Output
Event handlers working on new elements without re-attaching
Complexity
O(1) per event handler attachment
Common Mistakes
- ⚠Attaching event listeners to each new element individually
- ⚠Not checking event.target vs event.currentTarget
- ⚠Forgetting event.stopPropagation() when needed
- ⚠Using event delegation when direct binding is simpler
Problem
Demonstrate map, filter, reduce, find, some, every, and flatMap.
Input
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Output
Various transformations and aggregations
Complexity
O(n) for most array methods
Common Mistakes
- ⚠Mutating the original array inside callbacks
- ⚠Not returning a value from map() (results in undefined)
- ⚠Using reduce when simpler methods would work
- ⚠Off-by-one in reduce initial value
Problem
Use destructuring to extract values from objects and arrays with defaults and nesting.
Input
Nested object with user data
Output
Extracted and transformed values
Complexity
O(1) for destructuring operations
Common Mistakes
- ⚠Destructuring undefined values (causes TypeError)
- ⚠Not providing defaults for optional properties
- ⚠Confusing object destructuring with variable declaration
- ⚠Forgetting that destructuring creates a shallow copy
Problem
Use spread and rest operators for arrays, objects, and function parameters.
Input
Arrays and objects to merge/split
Output
New arrays and objects with spread/rest
Complexity
O(n) for spread operations on arrays/objects
Common Mistakes
- ⚠Assuming spread creates a deep copy (it's shallow only)
- ⚠Confusing spread (...) with rest (...) syntax
- ⚠Using spread for large arrays (slower than push)
- ⚠Not mutating the original when rest is expected
Problem
Create classes with inheritance, static methods, getters/setters, and private fields.
Input
A shape hierarchy with Circle and Rectangle
Output
Properly structured classes with encapsulation
Complexity
O(1) for most operations
Common Mistakes
- ⚠Using class syntax without calling super() in constructors
- ⚠Confusing #private fields with _ convention
- ⚠Forgetting that class bodies are in strict mode
- ⚠Not using static keyword correctly
Problem
Understand JavaScript prototype chain, prototype inheritance, and Object.create().
Input
Creating objects with prototype relationships
Output
Objects inheriting through prototype chain
Complexity
O(1) for prototype lookups
Common Mistakes
- ⚠Modifying Array.prototype (pollutes global prototype)
- ⚠Using __proto__ instead of Object.getPrototypeOf()
- ⚠Forgetting constructor property after prototype reassignment
- ⚠Confusing prototype with __proto__
Problem
Implement function currying that transforms multi-argument functions.
Input
A function that takes multiple arguments
Output
Curried version that can be called with one arg at a time
Complexity
O(1) per curried call
Common Mistakes
- ⚠Not preserving 'this' context in curried functions
- ⚠Forgetting to handle partial application correctly
- ⚠Over-currying simple functions
- ⚠Using currying where composition would be clearer
Problem
Implement a generic memoization function that caches function results.
Input
Expensive pure function
Output
Cached results for repeated inputs
Complexity
O(1) for cached lookups, O(n) for first computation
Common Mistakes
- ⚠Using JSON.stringify for complex object keys (slow, loses types)
- ⚠Not implementing cache eviction (memory leak)
- ⚠Memoizing functions with side effects
- ⚠Forgetting that memoization only works on pure functions
Problem
Implement deep cloning that handles nested objects, arrays, and special types.
Input
Complex nested object with circular references
Output
Independent deep copy
Complexity
O(n) where n is total number of nested properties
Common Mistakes
- ⚠JSON.parse(JSON.stringify()) loses Date, undefined, functions
- ⚠Not handling circular references (causes stack overflow)
- ⚠Shallow copying nested objects
- ⚠Losing prototype chain in cloned objects
Problem
Flatten a deeply nested array to arbitrary depth.
Input
[1, [2, [3, [4]], 5]]
Output
[1, 2, 3, 4, 5]
Complexity
O(n) where n is total number of elements
Common Mistakes
- ⚠Stack overflow with very deep arrays (use iterative approach)
- ⚠Not handling sparse arrays correctly
- ⚠Confusing flat() depth parameter behavior
- ⚠Performance issues with spread operator on large arrays
Problem
Parse and manipulate URL search parameters.
Input
URL with query parameters
Output
Parsed parameters and modified URLs
Complexity
O(n) where n is number of parameters
Common Mistakes
- ⚠Not encoding special characters in parameters
- ⚠Using string concatenation instead of URLSearchParams
- ⚠Forgetting that URLSearchParams modifies in place
- ⚠Not handling duplicate parameter names
Problem
Implement CRUD operations for localStorage with error handling and expiry.
Input
Various data types to store
Output
Persistent data with TTL support
Complexity
O(1) for basic operations
Common Mistakes
- ⚠Not using try-catch for QuotaExceededError
- ⚠Storing complex objects without JSON.stringify
- ⚠Not implementing TTL for session-like data
- ⚠Assuming localStorage is synchronous in all browsers
Problem
Implement robust API fetching with retries, timeouts, and error handling.
Input
API endpoint with potential failures
Output
Reliable data fetching with retry logic
Complexity
O(1) per fetch, O(retries) in worst case
Common Mistakes
- ⚠Not checking response.ok (fetch only rejects on network error)
- ⚠Not implementing exponential backoff for retries
- ⚠Not aborting fetch when component unmounts
- ⚠Forgetting to set Content-Type header for JSON
Problem
Build a reusable form validation system with custom rules and error messages.
Input
A form with various field types
Output
Validated form with error messages
Complexity
O(n) per validation pass
Common Mistakes
- ⚠Validating only on submit instead of on blur/input
- ⚠Not preventing default form submission
- ⚠Client-side validation can be bypassed (must also validate server-side)
- ⚠Not providing accessible error messages
Problem
Create smooth animations using requestAnimationFrame with proper timing.
Input
An element to animate across the screen
Output
Smooth 60fps animation with easing
Complexity
O(1) per frame, O(n) for n animated elements
Common Mistakes
- ⚠Using setInterval instead of requestAnimationFrame
- ⚠Not calculating delta time for frame-rate independent animation
- ⚠Forgetting to cancel animation frame on unmount
- ⚠Animating layout properties (width, height) instead of transform/opacity
php
20 problemsProblem
Reverse a string in PHP using built-in functions and manual approach.
Input
hello
Output
olleh
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Not handling multibyte strings (use mb_strrev or preg_match)
- ⚠Assuming strlen works with multibyte characters
- ⚠Forgetting PHP string indexing starts at 0
Problem
Check if a string is a palindrome in PHP.
Input
racecar
Output
true
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Not normalizing case before comparison
- ⚠Using strrev for comparison instead of two-pointer (creates unnecessary copy)
- ⚠Not stripping non-alphanumeric characters
Problem
Compute factorial using recursion and iteration in PHP.
Input
5
Output
120
Complexity
O(n) time, O(1) iterative / O(n) recursive
Common Mistakes
- ⚠Not handling negative input
- ⚠Using int instead of bcmath for large numbers
- ⚠Stack overflow for large n with recursion
Problem
Generate Fibonacci numbers using iteration.
Input
10
Output
0 1 1 2 3 5 8 13 21 34
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Using recursion without memoization
- ⚠Integer overflow for large n (use GMP extension)
- ⚠Off-by-one in array index
Problem
Check if a number is prime in PHP.
Input
17
Output
true
Complexity
O(sqrt(n)) time, O(1) space
Common Mistakes
- ⚠Not handling n < 2
- ⚠Checking divisibility up to n instead of sqrt(n)
- ⚠Including 1 as a prime number
Problem
Demonstrate PHP array functions: map, filter, reduce, sort, and merge.
Input
[3, 1, 4, 1, 5, 9, 2, 6]
Output
Various array transformations
Complexity
O(n) for most operations
Common Mistakes
- ⚠Using foreach instead of array_map for functional style
- ⚠Modifying array while iterating with foreach
- ⚠Confusing array_merge with + operator for arrays
- ⚠Not using strict comparison in array_filter
Problem
Use PHP string functions: substr, strpos, str_replace, explode, implode, preg_match.
Input
Various string operations
Output
Transformed strings
Complexity
O(n) for most string operations
Common Mistakes
- ⚠Using strlen/substr on multibyte strings (use mb_ functions)
- ⚠Confusing strpos returning false vs 0
- ⚠Not escaping special characters in regex patterns
- ⚠Forgetting that PHP strings are byte arrays by default
Problem
Work with PHP associative arrays for data manipulation and grouping.
Input
Array of user records
Output
Grouped, sorted, and filtered data
Complexity
O(n) for most operations
Common Mistakes
- ⚠Using array_key_exists when isset would be faster
- ⚠Not initializing nested arrays before pushing
- ⚠Confusing = (assignment) with == (comparison)
- ⚠Using count() on large arrays in loops (cache the value)
Problem
Read from and write to files with proper error handling in PHP.
Input
Write and read a CSV file
Output
File contents properly handled
Complexity
O(n) for file operations
Common Mistakes
- ⚠Not checking return values of file operations
- ⚠Not using file locking for concurrent writes
- ⚠Not closing file handles
- ⚠Using file_get_contents for large files (memory issue)
Problem
Handle HTML form submissions with validation and CSRF protection.
Input
A form POST request with user data
Output
Validated and sanitized form data
Complexity
O(1) for form processing
Common Mistakes
- ⚠Not implementing CSRF protection
- ⚠Using htmlspecialchars without ENT_QUOTES flag
- ⚠Not validating server-side (client-side can be bypassed)
- ⚠Using $_POST directly without filter_input
Problem
Implement secure session management with timeout and regeneration.
Input
User login flow with session handling
Output
Secure session with timeout protection
Complexity
O(1) for session operations
Common Mistakes
- ⚠Not regenerating session ID after login
- ⚠Storing sensitive data in session without encryption
- ⚠Not implementing session timeout
- ⚠Forgetting to set session cookie security flags
Problem
Use PDO for database operations with prepared statements and transactions.
Input
Database CRUD operations
Output
Secure database interactions with PDO
Complexity
O(n) for batch operations
Common Mistakes
- ⚠Using query() instead of prepare/execute with user input
- ⚠Not using transactions for multi-step operations
- ⚠Emulating prepares which can cause type issues
- ⚠Not setting proper error mode
Problem
Use preg_match, preg_match_all, preg_replace, and preg_split for text processing.
Input
Text with emails, phones, and dates
Output
Extracted and transformed data
Complexity
O(n) for most regex operations
Common Mistakes
- ⚠Not escaping special regex characters in patterns
- ⚠Using preg_match when preg_match_all is needed
- ⚠Not using non-capturing groups (?:) when captures aren't needed
- ⚠Forgetting PREG_SPLIT_NO_EMPTY flag
Problem
Encode and decode JSON with error handling and type management.
Input
PHP arrays and objects
Output
JSON strings and parsed data
Complexity
O(n) for encode/decode
Common Mistakes
- ⚠Not checking json_last_error() after decode
- ⚠Losing precision on large integers in JSON
- ⚠Forgetting that json_decode returns null on error (not false)
- ⚠Not using JSON_THROW_ON_ERROR for PHP 7.3+
Problem
Implement custom exceptions, error handlers, and exception chaining.
Input
Various error scenarios
Output
Properly handled errors with context
Complexity
O(1) for exception handling
Common Mistakes
- ⚠Catching generic Exception instead of specific types
- ⚠Not re-throwing exceptions properly (losing stack trace)
- ⚠Using exceptions for normal control flow
- ⚠Not implementing __toString() for custom exceptions
Problem
Create PHP classes with inheritance, interfaces, and abstract classes.
Input
A payment processing system
Output
Properly structured OOP code with polymorphism
Complexity
O(1) for most operations
Common Mistakes
- ⚠Not using type hints for method parameters and return values
- ⚠Using public properties instead of getters/setters
- ⚠Not following SOLID principles
- ⚠Confusing abstract classes with interfaces
Problem
Use PHP traits for code reuse with conflict resolution.
Input
Multiple traits with overlapping methods
Output
Class using traits with proper conflict resolution
Complexity
O(1) for trait methods
Common Mistakes
- ⚠Not resolving method conflicts when using multiple traits
- ⚠Using traits when interfaces/inheritance would be better
- ⚠Traits cannot have constants (use interfaces instead)
- ⚠Overusing traits leading to complex dependency chains
Problem
Organize PHP code with namespaces and use statements.
Input
Multiple classes that need organization
Output
Namespaced code with proper autoloading
Complexity
O(1) for namespace resolution
Common Mistakes
- ⚠Not following PSR-4 autoloading standard
- ⚠Using global namespace instead of relative imports
- ⚠Circular namespace dependencies
- ⚠Forgetting to require autoloader
Problem
Set up a Composer project with PSR-4 autoloading and custom scripts.
Input
A PHP project structure
Output
Working autoloader with dependencies
Complexity
O(1) for autoloading
Common Mistakes
- ⚠Not running composer dump-autoload after changes
- ⚠Using require/include instead of autoloading
- ⚠Not differentiating autoload vs autoload-dev
- ⚠Polluting global namespace with helpers
Problem
Implement proper security measures against XSS, SQL injection, and CSRF.
Input
User input that could be malicious
Output
Properly sanitized and escaped output
Complexity
O(1) for most security operations
Common Mistakes
- ⚠Using htmlentities instead of htmlspecialchars (over-encoding)
- ⚠Not using prepared statements for database queries
- ⚠Storing passwords without hashing
- ⚠Not setting security headers
assembly
15 problemsProblem
Write a hello world program in x86-64 Linux assembly using syscalls.
Input
None
Output
Hello, World!
Complexity
O(1)
Common Mistakes
- ⚠Using wrong syscall numbers (different between x86 and x86-64)
- ⚠Forgetting to include newline (10) in the message
- ⚠Not zeroing rdi with xor before using it as a value
- ⚠Mixing up 32-bit and 64-bit register names
Problem
Reverse a string in place using x86-64 assembly.
Input
String 'hello'
Output
String 'olleh'
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Using wrong comparison (cmp should be between pointers, not values)
- ⚠Forgetting to increment/decrement pointers
- ⚠Using 32-bit registers in 64-bit mode
- ⚠Off-by-one in end pointer calculation
Problem
Calculate factorial of a number using recursion in x86-64 assembly.
Input
5
Output
120
Complexity
O(n) time, O(n) stack space
Common Mistakes
- ⚠Not preserving callee-saved registers
- ⚠Forgetting to set up stack frame (push rbp / mov rbp, rsp)
- ⚠Using imul for unsigned when result can overflow
- ⚠Not restoring stack pointer after call
Problem
Generate Fibonacci sequence iteratively in x86-64 assembly.
Input
10
Output
0 1 1 2 3 5 8 13 21 34
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Not saving/restoring registers across function calls
- ⚠Using loop instruction with wrong register (rcx)
- ⚠Not handling the number-to-string conversion properly
- ⚠Register clobbering between loop iterations
Problem
Calculate the sum of all elements in an integer array.
Input
[1, 2, 3, 4, 5]
Output
15
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Using wrong stride (add rsi, 2 for 16-bit, add rsi, 8 for 64-bit)
- ⚠Not zeroing the accumulator before the loop
- ⚠Using 32-bit eax when result might exceed 32 bits
- ⚠Not accounting for data alignment
Problem
Find the maximum element in an integer array.
Input
[3, 1, 4, 1, 5, 9, 2, 6]
Output
9
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Using jge instead of jg (signed vs unsigned comparison)
- ⚠Starting comparison from index 0 instead of index 1
- ⚠Not using the correct comparison instruction for the data size
- ⚠Register size mismatch (comparing 32-bit with 64-bit)
Problem
Implement bubble sort for an integer array in x86-64 assembly.
Input
[5, 3, 1, 4, 2]
Output
[1, 2, 3, 4, 5]
Complexity
O(n^2) time, O(1) space
Common Mistakes
- ⚠Not saving outer loop counter before inner loop
- ⚠Forgetting the swapped optimization flag
- ⚠Using wrong comparison (jl instead of jle for stable sort)
- ⚠Stack misalignment from push/pop mismatch
Problem
Implement binary search on a sorted array in x86-64 assembly.
Input
[1, 2, 3, 4, 5, 6, 7, 8], target = 5
Output
Index: 4
Complexity
O(log n) time, O(1) space
Common Mistakes
- ⚠Integer overflow in mid calculation (use left + (right-left)/2)
- ⚠Off-by-one in comparison (jg vs jge)
- ⚠Using wrong comparison for signed/unsigned
- ⚠Not properly calculating array element address (base + index*4)
Problem
Implement push, pop, and peek operations using the stack in x86-64 assembly.
Input
Push 10, 20, 30 then pop twice
Output
Popped values: 30, 20
Complexity
O(1) for push/pop/peek
Common Mistakes
- ⚠Not maintaining stack alignment (16-byte boundary)
- ⚠Popping into wrong register
- ⚠Not cleaning up stack before exit
- ⚠Using rsp directly instead of push/pop instructions
Problem
Demonstrate proper function calling convention with stack frame setup.
Input
Multiple function calls with parameters
Output
Proper function call and return
Complexity
O(1) per function call
Common Mistakes
- ⚠Not preserving callee-saved registers (rbx, rbp, r12-r15)
- ⚠Not aligning stack to 16 bytes before call
- ⚠Mixing up caller-saved and callee-saved registers
- ⚠Not using proper stack frame setup/teardown
Problem
Calculate the length of a null-terminated string.
Input
"Hello, World!"
Output
13
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Using cmp with full register instead of byte comparison
- ⚠Not zeroing the counter before the loop
- ⚠Forgetting the null terminator check
- ⚠Using scasb which is faster but less readable
Problem
Copy a null-terminated string from source to destination.
Input
Source: "Hello"
Output
Destination contains "Hello"
Complexity
O(n) time, O(n) space
Common Mistakes
- ⚠Not copying the null terminator
- ⚠Using movsb without setting direction flag
- ⚠Buffer overflow if dest is too small
- ⚠Not saving/restoring dest pointer for return value
Problem
Check if a string is a palindrome using two pointers in assembly.
Input
"racecar"
Output
1 (true)
Complexity
O(n) time, O(1) space
Common Mistakes
- ⚠Not properly calculating string length
- ⚠Using wrong comparison direction for left/right pointers
- ⚠Not saving registers across function calls
- ⚠Byte comparison vs word comparison issues
Problem
Allocate and free dynamic memory using the Linux brk syscall.
Input
Allocate 100 bytes, write data, then free
Output
Successfully allocated and used memory
Complexity
O(1) for brk, O(n) for actual allocation with fragmentation
Common Mistakes
- ⚠Not checking if brk syscall failed
- ⚠Using brk for small allocations (mmap is better for large)
- ⚠Not aligning allocation to word boundary
- ⚠Simplified free doesn't handle coalescing
Problem
Read from and write to files using Linux system calls.
Input
Read from /tmp/input.txt, write to /tmp/output.txt
Output
File contents copied
Complexity
O(n) where n is file size
Common Mistakes
- ⚠Not checking return values of syscalls
- ⚠Using wrong flags for open (O_CREAT needs O_TRUNC to overwrite)
- ⚠Not closing file descriptors (resource leak)
- ⚠Buffer too small for large files (need loop)
Ready to Practice?
Apply what you've learned with our compiler and DSA problems.