49 Coding Challenges That You Have to Try (Any OOP Language)

Nata Sulakvelidze
7 min readJul 27, 2024

--

Coding challenges are a great way to improve your programming skills, think critically, and learn new concepts. It doesn’t matter if you’re a beginner or an experienced developer. These challenges are designed to help you level up.

Photo by Mohammad Rahmani on Unsplash

Without further ado, here’s a list of 49 coding challenges that you should try, applicable to any Object-Oriented Programming (OOP) language like Java, C++, Python, or C#.

I strongly encourage you to try solving each challenge on your own before checking the solutions. If you need help, solutions are provided via links at the end of the article (Python and C++ codes included).

Beginner Challenges

Photo by Clay Banks on Unsplash

Challenge 1 (Don’t skip this one):

Hello World: Write a program that prints “Hello, World!” to the console.

  • Input: None
  • Output: “Hello, World!”

Challenge 2:

FizzBuzz: Print numbers from 1 to 100. For multiples of 3, print “Fizz”; for multiples of 5, print “Buzz”; for multiples of both, print “FizzBuzz”.

  • Input: None
  • Output: 1, 2, “Fizz”, 4, “Buzz”, …, “FizzBuzz”

Challenge 3 (My absolute favorite):

Palindrome Check: Check if a given string is a palindrome.

  • Input: “racecar”
  • Output: True

Challenge 4:

Factorial Calculation: Write a function to compute the factorial of a number.

  • Input: 5
  • Output: 120

Challenge 5 (Gotta love this one):

Reverse a String: Reverse the characters in a given string.

  • Input: “hello”
  • Output: “olleh”

Challenge 6:

Sum of Natural Numbers: Compute the sum of all natural numbers up to a given number.

  • Input: 10
  • Output: 55

Challenge 7:

Leap Year Checker: Determine if a given year is a leap year.

  • Input: 2020
  • Output: True

Challenge 8:

Prime Number Checker: Check if a number is a prime.

  • Input: 11
  • Output: True

Challenge 9 (Looks easy) :

Fibonacci Sequence: Generate the first N numbers in the Fibonacci sequence.

  • Input: 5
  • Output: [0, 1, 1, 2, 3]

Challenge 10:

Array Max and Min: Find the maximum and minimum elements in an array.

  • Input: [1, 3, 5, 2, 8]
  • Output: Max: 8, Min: 1

Intermediate Challenges

Photo by Philippa Rose-Tite on Unsplash

Challenge 11 (Let’s see what you got):

Binary Search: Implement binary search on a sorted array.

  • Input: [1, 2, 3, 4, 5, 6], target: 4
  • Output: Index: 3

Challenge 12:

Anagram Check: Determine if two strings are anagrams.

  • Input: “listen”, “silent”
  • Output: True

Challenge 13:

Merge Sort: Implement the merge sort algorithm.

  • Input: [4, 2, 5, 1, 3]
  • Output: [1, 2, 3, 4, 5]

Challenge 14:

Linked List Implementation: Create and manipulate a linked list.

  • Input: Add 1, Add 2, Remove 1
  • Output: [2]

Challenge 15 (Getting harder, huh?):

Queue Using Two Stacks: Implement a queue using two stacks.

  • Input: Enqueue 1, Enqueue 2, Dequeue
  • Output: Dequeued: 1

Challenge 16:

Balanced Parentheses: Check if a string of parentheses is balanced.

  • Input: “((()))”
  • Output: True

Challenge 17:

Longest Substring Without Repeating Characters: Find the longest substring without repeating characters.

  • Input: “abcabcbb”
  • Output: “abc”

Challenge 18 (It gets easier, I promise):

Sum of Digits: Calculate the sum of digits of a number until a single digit is obtained.

  • Input: 38
  • Output: 2 (3 + 8 = 11, 1 + 1 = 2)

Challenge 19:

Find Duplicates in Array: Identify duplicates in an array.

  • Input: [1, 2, 3, 1, 4, 2]
  • Output: [1, 2]

Challenge 20:

Rotate Matrix: Rotate a 2D matrix by 90 degrees.

  • Input: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
  • Output: [[7, 4, 1], [8, 5, 2], [9, 6, 3]]

Advanced Challenges

Photo by yns plt on Unsplash

Challenge 21 (Who doesn’t love Sudoku?!):

Sudoku Solver: Solve a Sudoku puzzle programmatically.

  • Input: 9x9 Sudoku grid with some cells filled
  • Output: Completed 9x9 Sudoku grid

Challenge 22:

Knapsack Problem: Solve the 0/1 knapsack problem using dynamic programming.

  • Input: Weights: [1, 3, 4], Values: [15, 20, 30], Capacity: 4
  • Output: Maximum Value: 35

Challenge 23:

LRU Cache Implementation: Design and implement an LRU cache.

  • Input: Set 1=1, Set 2=2, Get 1, Set 3=3, Get 2
  • Output: 1, -1

Challenge 24:

Word Ladder: Find the shortest transformation sequence from one word to another.

  • Input: Begin: “hit”, End: “cog”, Word List: [“hot”, “dot”, “dog”, “lot”, “log”, “cog”]
  • Output: [“hit”, “hot”, “dot”, “dog”, “cog”]

Challenge 25 (Don’t give up):

K-th Largest Element: Find the k-th largest element in an array.

  • Input: [3, 2, 1, 5, 6, 4], k=2
  • Output: 5

Challenge 26:

Graph Traversal: Implement depth-first and breadth-first search.

  • Input: Graph: {A: [B, C], B: [D, E], C: [F, G]}, Start: A
  • Output: DFS: [A, B, D, E, C, F, G], BFS: [A, B, C, D, E, F, G]

Challenge 27:

Dijkstra’s Algorithm: Find the shortest path in a weighted graph.

  • Input: Graph: {A: {B: 1, C: 4}, B: {C: 2, D: 5}, C: {D: 1}}, Start: A
  • Output: Shortest Path: {A: 0, B: 1, C: 3, D: 4}

Challenge 28:

Median of Two Sorted Arrays: Find the median of two sorted arrays.

  • Input: [1, 3], [2]
  • Output: 2.0

Challenge 29 (Keep Going):

N-Queens Problem: Solve the N-Queens problem using backtracking.

  • Input: 4
  • Output: [[“.Q..”, “…Q”, “Q…”, “..Q.”], [“..Q.”, “Q…”, “…Q”, “.Q..”]]

Challenge 30:

Trie Implementation: Implement a trie (prefix tree) for efficient word storage and search.

  • Input: Insert “hello”, Insert “world”, Search “hello”
  • Output: True

Coding Challenges with Data Structures

Photo by Prateek Katyal on Unsplash

Challenge 31 (I know you can do it):

Binary Tree Inorder Traversal: Perform an inorder traversal of a binary tree.

  • Input: [1, None, 2, 3]
  • Output: [1, 3, 2]

Challenge 32:

Graph Cycle Detection: Detect a cycle in a graph using DFS.

  • Input: Graph: {A: [B], B: [C], C: [A]}
  • Output: True

Challenge 33:

Max Heap Implementation: Implement a max heap.

  • Input: Insert 3, Insert 2, Insert 15, Extract Max
  • Output: 15

Challenge 34 (Learning some new skills, huh?):

Inorder Successor in BST: Find the inorder successor of a node in a BST.

  • Input: BST: [20, 8, 22, 4, 12, None, None, None, None, 10, 14], Node: 8
  • Output: 10

Challenge 35:

Find All Paths in a Graph: Find all paths between two nodes in a graph.

  • Input: Graph: {A: [B, C], B: [C, D], C: [D]}, Start: A, End: D
  • Output: [[“A”, “B”, “D”], [“A”, “B”, “C”, “D”], [“A”, “C”, “D”]]

Challenge 36:

Word Search in Grid: Search for a word in a 2D grid of characters.

  • Input: Board: [[“A”, “B”, “C”, “E”], [“S”, “F”, “C”, “S”], [“A”, “D”, “E”, “E”]], Word: “ABCCED”
  • Output: True

Challenge 37:

Implement Stack Using Queues: Implement a stack using two queues.

  • Input: Push 1, Push 2, Pop
  • Output: 2

Challenge 38 (You are doing great, go on):

Sort a Stack: Sort a stack using another stack.

  • Input: [34, 3, 31, 98, 92, 23]
  • Output: [3, 23, 31, 34, 92, 98]

Challenge 39:

Circular Queue Implementation: Implement a circular queue.

  • Input: Enqueue 1, Enqueue 2, Dequeue, Enqueue 3
  • Output: [2, 3]

Algorithmic Challenges

Photo by Tim Gouw on Unsplash

Challenge 40 (Skills are developed through practice):

Merge Intervals: Merge overlapping intervals.

  • Input: [[1, 3], [2, 6], [8, 10], [15, 18]]
  • Output: [[1, 6], [8, 10], [15, 18]]

Challenge 41:

Search in Rotated Sorted Array: Search for an element in a rotated sorted array.

  • Input: [4, 5, 6, 7, 0, 1, 2], Target: 0
  • Output: Index: 4

Challenge 42:

Count Inversions in Array: Count the number of inversions needed to sort the array.

  • Input: [8, 4, 2, 1]
  • Output: 6

Challenge 43 (You definitely got this one!):

Find the Missing Number: Find the missing number in a given array of integers.

  • Input: [3, 0, 1]
  • Output: 2

Challenge 44:

Longest Increasing Subsequence: Find the length of the longest increasing subsequence.

  • Input: [10, 9, 2, 5, 3, 7, 101, 18]
  • Output: 4

Challenge 45:

Minimum Window Substring: Find the smallest substring containing all characters of another string.

  • Input: S: “ADOBECODEBANC”, T: “ABC”
  • Output: “BANC”

Challenge 46 (You are almost done!):

Graph Coloring Problem: Determine if a graph can be colored with at most M colors.

  • Input: Graph: {0: [1, 2], 1: [0, 2], 2: [0, 1]}, M: 2
  • Output: True

Challenge 47:

Topological Sort: Perform a topological sort on a directed acyclic graph.

  • Input: Graph: {5: [2, 0], 4: [0, 1], 2: [3], 3: [1]}
  • Output: [4, 5, 2, 3, 1, 0]

Challenge 48:

Matrix Chain Multiplication: Find the optimal way to multiply a chain of matrices.

  • Input: Dimensions: [10, 20, 30, 40, 30]
  • Output: Minimum number of multiplications: 30000

Challenge 49 (You are near the finish line):

Travelling Salesman Problem: Solve the travelling salesman problem using dynamic programming.

  • Input: Distance matrix: [[0, 10, 15, 20], [10, 0, 35, 25], [15, 35, 0, 30], [20, 25, 30, 0]]
  • Output: Minimum cost: 80
Photo by sandra lansue on Unsplash

I really hope you enjoyed the challenges, let me know if you have any questions, and feel free to share some feedback.

P.S. If you want to see more of this content, make sure to follow me and subscribe 🙌

Links to solutions with explanations (Please, try to do it yourself, first) :

Beginner Challenges

Intermediate Challenges

Advanced Challenges

Coding Challenges with Data Structures

Algorithmic Challenges

--

--