Free coding practice in Python, JavaScript and SQL
Solve placement-style coding problems in your browser: Python, JavaScript and SQL with sample runs, hidden tests, hints and solutions. Free.
Arrays & Hashing
Counting, prefix sums and lookups with a dictionary or set.
- Majority Element (easy): Find the candidate who received more than half of all the votes.
- Grade Report (easy): Read the marks of N students and print how many fall in each of the grades A, B, C, D and F.
- Rotate Array (medium): Shift a list to the right by k places, wrapping the end around to the front.
- Matrix Diagonal Difference (medium): Read an N × N matrix and print the absolute difference between the sums of its two diagonals.
- Top K Frequent Elements (medium): Return the k numbers that appear most often, with a fixed rule for ties.
- Subarray Sum Equals K (medium): Count the contiguous stretches of a list whose values add up to exactly k.
- Rotate Image (Matrix) (medium): Return a square grid turned 90 degrees clockwise.
Strings
Characters, words, anagrams and text processing.
- Count the Vowels (easy): Count how many vowels a piece of text has, in either case.
- Valid Anagram (easy): Decide whether two words use exactly the same letters the same number of times.
- First Unique Character (easy): Find the position of the first letter that appears only once in a word.
- Longest Common Prefix (easy): Find the longest beginning that every word in a list shares.
- Reverse Words in a String (easy): Reverse the order of the words in a sentence and tidy the spacing to single spaces.
- String Compression (easy): Shrink runs of repeated letters to letter-and-count, keeping the original when that is not shorter.
- Roman to Integer (easy): Convert a Roman numeral such as MCMXLVII into the ordinary number it stands for.
Two Pointers & Sliding Window
Two indices moving through a list or a window that grows and shrinks.
- Move Zeroes (easy): Push every zero to the end of a list while keeping the other numbers in their order.
- Merge Two Sorted Lists (easy): Combine two sorted mark lists into one sorted list.
- Two Sum II (Sorted List) (easy): In a sorted price list, find the two positions whose prices add up to a target.
- Valid Palindrome (easy): Check whether a sentence reads the same both ways once you ignore case, spaces and punctuation.
- Container With Most Water (medium): Pick two poles in a row so that a sheet stretched between them holds the most water.
- Longest Substring Without Repeating Characters (medium): Find the length of the longest stretch of a string in which no character appears twice.
- Minimum Size Subarray Sum (medium): Find the fewest consecutive days of sales that together reach a target amount.
- 3Sum (medium): List every distinct group of three ledger entries that cancel out to zero.
- Trapping Rain Water (hard): Work out how much rain water stays trapped between bars of different heights.
- Longest Repeating Character Replacement (hard): Repaint at most k tiles to get the longest run of a single colour.
Stacks & Queues
Brackets, next greater element, monotonic stacks and deques.
- Balanced Brackets (easy): Check whether every round, square and curly bracket in a string is closed in the right order.
- Next Greater Element (medium): For each day, find the next later day with a strictly higher price, or -1 if there is none.
- Evaluate Reverse Polish Notation (medium): Work out the value of an integer expression written in postfix order with + - * and whole-number division.
- Min Stack (medium): Run push, pop, top and min operations on a stack where min must be answered instantly.
- Largest Rectangle in Histogram (hard): Find the area of the largest rectangle that fits inside a row of bars of width 1.
- Sliding Window Maximum (hard): Report the largest value in every window of k consecutive numbers as the window slides along a list.
Binary Search
Halving a sorted range, or searching on the answer.
- Integer Square Root (easy): Return the whole-number part of the square root of n without a built-in square root.
- Search Insert Position (easy): Find where a value is, or where it would go, in a sorted list of distinct numbers.
- Search in Rotated Sorted Array (medium): Search a sorted list that has been cut and rejoined, in logarithmic time.
- Find First and Last Position of Element in Sorted Array (medium): In a sorted list, find the first and last index of a value, or [-1, -1] if it is absent.
- Koko Eating Bananas (medium): Find the slowest eating speed that still finishes every pile of bananas within h hours.
- Find Minimum in Rotated Sorted Array (medium): A sorted list of distinct numbers was rotated; find its smallest value in O(log n) time.
Sorting & Greedy
Sort first, then take the best choice at each step.
- Best Time to Buy and Sell Stock (easy): Buy a share on one day and sell it on a later day for the biggest profit.
- Merge Intervals (medium): Combine overlapping booking slots of a seminar hall into the fewest blocks.
- Meeting Rooms II (medium): Find how many rooms a placement drive needs so that no two interviews clash.
- Jump Game (medium): Decide whether you can hop from the first stepping stone to the last one.
- Boats to Save People (medium): Ferry everyone across the Ganga with the fewest boats, two people at most per boat.
Recursion & Backtracking
Subsets, permutations and choices tried and undone.
- Subsets (medium): List every possible selection, from none to all, of a set of distinct numbers.
- Permutations (medium): List every order in which a set of distinct numbers can be arranged.
- Generate Parentheses (medium): List every correctly matched string of n pairs of round brackets.
- Combination Sum (medium): Find every way to reach a target total using given values, each as many times as you like.
- N-Queens (hard): Count the ways to place n queens on an n x n chessboard so that no two attack each other.
Graphs & Grids
BFS, DFS, islands, shortest paths and dependencies.
- Flood Fill (easy): Repaint a connected region of same-coloured cells, like the paint bucket tool.
- Number of Islands (medium): Count the separate pieces of land on a map made of land and water cells.
- Shortest Path in a Binary Grid (medium): Find the fewest moves from the top-left to the bottom-right of a grid with blocked cells.
- Course Schedule (medium): Decide whether every course can be completed when some courses must be taken before others.
- Number of Connected Components (medium): Count the separate groups in a network given its nodes and two-way links.
- Rotting Oranges (medium): Find how many minutes it takes for rot to spread to every orange in a crate, or -1.
Dynamic Programming
Build the answer from answers to smaller versions of the problem.
- Climbing Stairs (easy): Count the ways to climb n steps when each move covers one or two steps.
- Maximum Subarray (Kadane) (medium): Find the best total over any stretch of consecutive days in a profit and loss record.
- House Robber (medium): Pick values from a list for the largest total without taking two neighbours.
- Longest Increasing Subsequence (medium): Find the length of the longest strictly increasing subsequence of a list.
- Coin Change (medium): Find the fewest coins that add up to an amount, or -1 when the amount cannot be made.
- Unique Paths with Obstacles (medium): Count the routes from the top-left to the bottom-right of a grid, moving right or down and avoiding blocked cells.
- Word Break (medium): Decide whether a string with no spaces can be cut into words that all appear in a given dictionary.
- Longest Common Subsequence (hard): Find the length of the longest sequence of characters that appears, in order, in both strings.
- Edit Distance (hard): Count the fewest single-letter inserts, deletes and replacements that turn one word into another.
Math & Number Theory
Digits, primes, GCD and other number problems.
- Sum of Digits (easy): Add up the digits of a whole number, such as a ticket or roll number.
- Fizz Buzz (easy): Play the classroom counting game: say Fizz, Buzz or FizzBuzz in place of some numbers.
- Leap Year Check (easy): Read a year and say whether it is a leap year, using the divisible by 4, 100 and 400 rule.
- GCD and LCM (easy): Read two positive integers and print their greatest common divisor and least common multiple.
- Armstrong Numbers in a Range (easy): List every Armstrong number between two limits, such as 153 = 1³ + 5³ + 3³.
- Prime Factorisation (medium): Write a number as a product of prime powers, printed in the form 2^3 * 3 * 5.
- Count Primes (medium): Count the prime numbers strictly below n using the Sieve of Eratosthenes.
Patterns & Printing
Star and number patterns, the warm-up of campus coding rounds.
- Star Triangle Pattern (easy): Print a left-aligned triangle of stars with N rows: one star on the first row, N on the last.
- Number Pyramid (easy): Print a centred pyramid where each row counts up from 1 to its row number and back down to 1.
- Pascal's Triangle (easy): Print the first N rows of Pascal's triangle, where each number is the sum of the two above it.
- Floyd's Triangle (easy): Print Floyd's triangle: the numbers 1, 2, 3, ... filled into rows of length 1, 2, 3, ...
- Hollow Diamond Pattern (medium): Print the outline of a diamond in stars: N rows down to its widest point and 2N - 1 rows in all.
SQL: Filtering & Sorting
SELECT, WHERE, ORDER BY, DISTINCT and CASE.
- Big UPI orders at the kirana shop (easy): Pick the UPI orders of 500 rupees or more from a kirana shop and list the biggest first.
- Distinct Movies by City (easy): List each city and movie pair from a cinema chain's bookings once, sorted by city and then by movie.
- Label Members by Activity Band (easy): Label every gym member REGULAR, OCCASIONAL or RARE from last month's visits, busiest members first.
SQL: Joins
Inner, left and self joins, and rows with no match.
- Books still out on loan (easy): Join loans to books and list every loan whose book has not come back to the library yet.
- Courses nobody has enrolled in (easy): Find the courses of an ed-tech company that do not have a single enrolment.
- Half-Centuries with Player and Team Names (easy): Join innings, players and teams to list every score of 50 or more with the player's and team's names.
- Earning more than the manager (medium): List the employees whose salary is higher than the salary of their own manager.
- Customers Who Bought in Both Months (medium): Find the pharmacy customers who made a purchase in October 2026 and also in November 2026.
- Products Never Returned (medium): List the products that no customer has ever sent back, when some return rows have no product at all.
SQL: Grouping & Aggregation
GROUP BY, HAVING and counting per group.
- Meals eaten per student (easy): Count how many meals each student has eaten in the hostel mess.
- Duplicate Emails (easy): Find every email that was used for more than one registration on an online test platform, with its count.
- Busy bus routes (medium): Find the bus routes with at least three booked tickets, with their ticket count and average fare.
- Share of Total Fare by City (medium): For a cab app, give each city's total fare and its share of the all-city total as a percentage to 2 decimals.
- Departments Above the Company Average Salary (medium): Find the startup departments whose average salary is higher than the average salary of the whole company.
SQL: Subqueries & CTEs
Nested queries, EXISTS and WITH.
- Students Above the Class Average (medium): List the students whose marks are higher than the average of their own class.
- Second-highest score at the academy (medium): Find the second-highest distinct score in a cricket academy's innings, or NULL when there is none.
- Latest Booking per Guest (medium): For every hotel guest, return their most recent stay by check-in date along with its room type.
- Third Highest Salary per Branch (hard): For every bank branch, find the third-highest distinct salary, leaving out branches with fewer than three.
SQL: Window Functions
Ranking, running totals, LAG/LEAD and streaks.
- Top two restaurants in every city (medium): For each city, find the two restaurants with the highest total order value on a food-delivery app.
- Running balance of UPI transfers (medium): Show every UPI transfer with the running balance of its account after that transfer.
- Month-over-Month Revenue Change (medium): Total a courier company's delivery charges per month and show the change from the previous month with LAG.
- Dense Rank of Students per Class (medium): Rank the students of each class by marks, with equal marks sharing a rank and no gaps after ties.
- Longest travel streak on a metro card (hard): For each metro card, find its longest run of consecutive travel days and the day that run began.
Practise by subject
- Quantitative Aptitude: Arithmetic, percentages, time and work, speed, probability and data interpretation: the numerical section of every fresher test.
- Logical Reasoning: Series, coding-decoding, arrangements, syllogisms and puzzles: the section that separates prepared candidates from the rest.
- Verbal Ability: Vocabulary, grammar, reading comprehension and sentence order: tested in nearly every IT services hiring exam.
- Technical & Programming: CS fundamentals, output prediction and pseudo-code: the technical MCQ round for IT roles.
- Python: Python quizzes by topic, from types and strings to classes and generators: output prediction and interview concepts.
- SQL: SQL quizzes by topic, from SELECT and joins to window functions: query output and concepts for analyst and developer roles.
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge · Test from a job description · LogicWiz Open: free team quiz · Free interview prep