Coding Challenge for Beginners | Coding Practice Challenges Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Start your coding journey with our Coding Challenge for Beginners! Here’s a simple coding challenge suitable for beginners. This challenge involves writing a function in a programming language of your choice.These fun practice coding challenges will help you learn the basics of programming and improve your problem-solving skills, giving you confidence as you learn to code.Coding Challenge for Beginners: From Easy to HardBeginners looking to enhance their coding skills should explore the GeeksforGeeks Practice Platform, which offers an extensive collection of beginner-friendly problems.Challenge 1: Print Numbers from 1 to 10 JavaScript for (let i = 1; i <= 10; i++) { console.log(i); } Challenge 2: Print Odd Numbers Less Than 100 JavaScript for (let i = 1; i < 100; i += 2) { console.log(i); } Challenge 3: Print Multiplication Table with 7 JavaScript for (let i = 1; i <= 10; i++) { console.log(`7 * ${i} = ${7 * i}`); } Challenge 4: Print All Multiplication Tables (1 to 10) JavaScript for (let i = 1; i <= 10; i++) { for (let j = 1; j <= 10; j++) { console.log(`${i} * ${j} = ${i * j}`); } } Challenge 5: Calculate Sum of Numbers from 1 to 10 JavaScript let sum = 0; for (let i = 1; i <= 10; i++) { sum += i; } console.log(sum); Challenge 6: Calculate 10! JavaScript function factorial(n) { if (n === 0 || n === 1) return 1; return n * factorial(n - 1); } console.log(factorial(10)); Challenge 7: Sum of Odd Numbers (10 to 30) JavaScript let sum = 0; for (let i = 11; i < 30; i += 2) { sum += i; } console.log(sum); Challenge 8: Celsius to Fahrenheit Conversion JavaScript function celsiusToFahrenheit(celsius) { return (celsius * 9/5) + 32; } console.log(celsiusToFahrenheit(30)); Challenge 9: Fahrenheit to Celsius Conversion JavaScript function fahrenheitToCelsius(fahrenheit) { return (fahrenheit - 32) * 5/9; } console.log(fahrenheitToCelsius(86)); Challenge 10: Sum of Numbers in an Array JavaScript let numbers = [1, 2, 3, 4, 5]; let sum = numbers.reduce((acc, curr) => acc + curr, 0); console.log(sum); Challenge 11: Average of Numbers in an Array JavaScript let numbers = [1, 2, 3, 4, 5]; let average = numbers.reduce((acc, curr) => acc + curr, 0) / numbers.length; console.log(average); Challenge 12: Positive Numbers in an Array (Solution 1) JavaScript function positiveNumbers(arr) { return arr.filter(num => num > 0); } console.log(positiveNumbers([-1, 2, -3, 4, -5])); Challenge 12: Positive Numbers in an Array (Solution 2) JavaScript function positiveNumbers(arr) { let result = []; for (let num of arr) { if (num > 0) { result.push(num); } } return result; } console.log(positiveNumbers([-1, 2, -3, 4, -5])); Challenge 12: Positive Numbers in an Array (Solution 3) JavaScript function positiveNumbers(arr) { let result = []; arr.forEach(num => { if (num > 0) { result.push(num); } }); return result; } console.log(positiveNumbers([-12, 22, -3, 41, -15])); Challenge 13: Maximum number in an array JavaScript let numbers = [5, 8, 3, 12, 7]; let max = Math.max(...numbers); console.log(max); Challenge 14: First 10 Fibonacci numbers without recursion JavaScript let fib = [0, 1]; for (let i = 2; i < 10; i++) { fib[i] = fib[i - 1] + fib[i - 2]; } console.log(fib); Challenge 15: nth Fibonacci number using recursion JavaScript function fibonacci(n) { if (n <= 1) { return n; } return fibonacci(n - 1) + fibonacci(n - 2); } console.log(fibonacci(5)); Challenge 16: Check if a number is prime JavaScript function isPrime(num) { if (num <= 1) return false; for (let i = 2; i <= Math.sqrt(num); i++) { if (num % i === 0) return false; } return true; } console.log(isPrime(11)); Challenge 17: Sum of digits of a positive integer JavaScript function sumOfDigits(num) { let sum = 0; while (num > 0) { sum += num % 10; num = Math.floor(num / 10); } console.log(sum); } sumOfDigits(123); Challenge 18: First 100 prime numbers JavaScript function generatePrimes(count) { let primes = []; for (let i = 2; primes.length < count; i++) { if (isPrime(i)) { primes.push(i); } } console.log(primes); } generatePrimes(100); Challenge 19: First "nPrimes" prime numbers greater than "startAt" JavaScript function generatePrimes(nPrimes, startAt) { let primes = []; let num = startAt + 1; while (primes.length < nPrimes) { if (isPrime(num)) { primes.push(num); } num++; } console.log(primes); } generatePrimes(5, 10); Challenge 20: Rotate an array to the left 1 position JavaScript let arr = [1, 2, 3, 4, 5]; let temp = arr.shift(); arr.push(temp); console.log(arr); Challenge 21: Rotate an array to the right 1 position JavaScript let arr = [1, 2, 3, 4, 5]; let temp = arr.pop(); arr.unshift(temp); console.log(arr); Challenge 22: Reverse an array JavaScript let arr = [1, 2, 3, 4, 5]; let reversed = arr.reverse(); console.log(reversed); Challenge 23: Reverse a string JavaScript let str = "Hello, Geeks!"; let reversed = str.split('').reverse().join(''); console.log(reversed); Challenge 24: Merge two arrays JavaScript let arr1 = [1, 2, 3]; let arr2 = [4, 5, 6]; let merged = arr1.concat(arr2); console.log(merged); Challenge 25: Elements in the first or second array but not both JavaScript let arr1 = [1, 2, 3, 4]; let arr2 = [3, 4, 5, 6]; let result = arr1.filter(num => !arr2.includes(num)).concat(arr2.filter(num => !arr1.includes(num))); console.log(result); Challenge 26: Elements in the first array but not in the second JavaScript let arr1 = [1, 2, 3, 4]; let arr2 = [3, 4, 5, 6]; let result = arr1.filter(num => !arr2.includes(num)); console.log(result); Challenge 27: Distinct elements in an array(Solution 1) JavaScript function getDistinctElements1(arr) { return Array.from(new Set(arr)); } let inputArray = [1, 2, 2, 3, 4, 4, 5]; let distinctArray1 = getDistinctElements1(inputArray); console.log(distinctArray1); Challenge 27: Distinct elements in an array(Solution 2) JavaScript function getDistinctElements2(arr) { return arr.filter((value, index, self) => self.indexOf(value) === index); } let inputArray = [1, 2, 2, 3, 4, 4, 5]; let distinctArray2 = getDistinctElements2(inputArray); console.log(distinctArray2); Challenge 28: Sum of first 100 prime numbers JavaScript function sumOfPrimes(count) { let primes = []; let sum = 0; for (let i = 2; primes.length < count; i++) { if (isPrime(i)) { primes.push(i); sum += i; } } console.log(sum); } sumOfPrimes(100); Challenge 29: Distance between the first 100 prime numbers JavaScript function primeDistance(count) { let primes = []; for (let i = 2; primes.length < count; i++) { if (isPrime(i)) { primes.push(i); } } let distance = []; for (let i = 1; i < primes.length; i++) { distance.push(primes[i] - primes[i - 1]); } console.log(distance); } primeDistance(100); Challenge 30: Add two positive numbers of indefinite size as strings(Solution 1) JavaScript function addStrings1(num1, num2) { let result = BigInt(num1) + BigInt(num2); return result.toString(); } let sum1 = addStrings1("12345678901234567890", "98765432109876543210"); console.log(sum1); Challenge 30: Add two positive numbers of indefinite size as strings(Solution 2) JavaScript function addStrings2(num1, num2) { let maxLength = Math.max(num1.length, num2.length); num1 = num1.padStart(maxLength, '0'); num2 = num2.padStart(maxLength, '0'); let carry = 0; let result = ''; for (let i = maxLength - 1; i >= 0; i--) { let digitSum = parseInt(num1[i]) + parseInt(num2[i]) + carry; carry = Math.floor(digitSum / 10); result = (digitSum % 10).toString() + result; } if (carry > 0) { result = carry.toString() + result; } return result; } let sum2 = addStrings2("12345678901234567890", "98765432109876543210"); console.log(sum2); Challenge 31: Number of words in a text(Solution 1) JavaScript function countWords1(text) { return text.split(/\s+/).filter(word => word !== '').length; } let inputText = "This is a sample text."; let wordCount1 = countWords1(inputText); console.log(wordCount1); Challenge 31: Number of words in a text(Solution 2) JavaScript function countWords2(text) { return text.split(/\s+/).filter(word => word !== '').length; } let inputText = "This is a sample text."; let wordCount2 = countWords2(inputText); console.log(wordCount2); Challenge 32: Capitalize the first letter of each word in a text JavaScript function capitalizeFirstLetter(text) { return text.replace(/\b\w/g, char => char.toUpperCase()); } let capitalizedText = capitalizeFirstLetter(inputText); console.log(capitalizedText); Challenge 33: Sum of numbers in a comma-delimited string JavaScript function sumNumbersInString(str) { let numbers = str.split(',').map(Number); return numbers.reduce((sum, num) => sum + num, 0); } let sumOfNumbers = sumNumbersInString(commaDelimitedString); console.log(sumOfNumbers); Challenge 34: Words inside a text JavaScript function getWordsArray(text) { return text.match(/\b\w+\b/g) || []; } let wordsArray = getWordsArray(inputText); console.log(wordsArray); Challenge 35: Convert CSV text to a bi-dimensional array JavaScript function csvToBiDimensionalArray(csvText) { return csvText.split('\n').map(row => row.split(',')); } let biDimensionalArray = csvToBiDimensionalArray(csvText); console.log(biDimensionalArray); Challenge 36: Convert a string to an array of characters JavaScript let str = "Hello, Geeks!"; let charArray = Array.from(str); console.log(charArray); Challenge 37: Convert a string to an array of ASCII codes JavaScript function stringToAsciiArray(text) { return text.split('').map(char => char.charCodeAt(0)); } let asciiArray = stringToAsciiArray(inputString); console.log(asciiArray); Challenge 38: Convert an array of ASCII codes to a string JavaScript function asciiArrayToString(asciiArray) { return String.fromCharCode(...asciiArray); } let asciiArray = [104, 101, 108, 108, 111]; let resultString = asciiArrayToString(asciiArray); console.log(resultString); Challenge 39: Implement the Caesar cipher JavaScript function caesarCipher(text, shift) { return text.replace(/[a-zA-Z]/g, char => { let baseCharCode = char.toLowerCase() === char ? 'a'.charCodeAt(0) : 'A'.charCodeAt(0); let charCode = char.charCodeAt(0); let shiftedCharCode = ((charCode - baseCharCode + shift) % 26 + 26) % 26 + baseCharCode; return String.fromCharCode(shiftedCharCode); }); } let inputText = "Hello, World!"; let encryptedText = caesarCipher(inputText, 3); console.log(encryptedText); Challenge 40: Bubble sort algorithm JavaScript function bubbleSort(arr) { let n = arr.length; for (let i = 0; i < n-1; i++) { for (let j = 0; j < n-i-1; j++) { if (arr[j] > arr[j+1]) { // swap arr[j] and arr[j+1] let temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } return arr; } let numbers = [64, 34, 25, 12, 22, 11, 90]; console.log(bubbleSort(numbers)); Challenge 41: Distance between two points defined by their coordinates JavaScript function calculateDistance(x1, y1, x2, y2) { return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)); } let distance = calculateDistance(1, 2, 4, 6); console.log(distance); Challenge 42: Check Circle Intersection JavaScript function areCirclesIntersecting(x1, y1, r1, x2, y2, r2) { let distance = calculateDistance(x1, y1, x2, y2); return distance < (r1 + r2); } let intersecting = areCirclesIntersecting(0, 0, 5, 8, 0, 5); console.log(intersecting); Challenge 43: Extract Column from 2D Array JavaScript function extractColumn(matrix, col) { return matrix.map(row => row[col]); } let matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; let column = extractColumn(matrix, 1); console.log(column); Challenge 44: Convert Binary String to Number JavaScript function binaryStringToNumber(binaryString) { return parseInt(binaryString, 2); } let binaryNumber = binaryStringToNumber("1101"); console.log(binaryNumber); Challenge 45: Sum of Numbers in Jagged Array JavaScript function sumJaggedArray(arr) { return arr.flat(Infinity).reduce((sum, num) => sum + num, 0); } let jaggedArray = [1, [2, [3, 4], 5], 6]; console.log(sumJaggedArray(jaggedArray)); Challenge 46: Find Maximum Number in Jagged Array(Solution 1) JavaScript function findMaxInJaggedArray(arr) { return Math.max(...arr.flat(Infinity)); } let jaggedArray = [1, [2, [3, 4], 5], 6]; console.log(findMaxInJaggedArray(jaggedArray)); Challenge 46: Find Maximum Number in Jagged Array(Solution 2) JavaScript function deepCopyJaggedArray(arr) { return JSON.parse(JSON.stringify(arr)); } let jaggedArray = [1, [2, [3, 4], 5], 6]; let copiedArray = deepCopyJaggedArray(jaggedArray); console.log(copiedArray); Challenge 47: Deep Copy Jagged Array JavaScript function deepCopyJaggedArray(arr) { return JSON.parse(JSON.stringify(arr)); } let jaggedArray = [1, [2, [3, 4], 5], 6]; let copiedArray = deepCopyJaggedArray(jaggedArray); console.log(copiedArray); Challenge 48: Longest Word(s) in a String JavaScript function longestWords(str) { let words = str.split(/\s+/); let maxLength = Math.max(...words.map(word => word.length)); return words.filter(word => word.length === maxLength); } let sentence = "The quick brown fox jumps over the lazy dog"; console.log(longestWords(sentence)); Challenge 49: Shuffle Array of Strings JavaScript function shuffleArray(arr) { return arr.sort(() => Math.random() - 0.5); } let stringsArray = ["apple", "banana", "orange", "grape"]; console.log(shuffleArray(stringsArray)); Challenge 50: Generate Unique Random Numbers JavaScript function generateUniqueRandomNumbers(n) { let numbers = Array.from({length: n}, (_, index) => index + 1); return shuffleArray(numbers); } let uniqueRandomNumbers = generateUniqueRandomNumbers(5); console.log(uniqueRandomNumbers); Challenge 51: Frequency of Characters in a String JavaScript function characterFrequency(str) { let frequency = {}; for (let char of str) { frequency[char] = (frequency[char] || 0) + 1; } return Object.entries(frequency).map(([character, occurrences]) => ({ character, occurrences })); } let inputString = "programming"; console.log(characterFrequency(inputString)); Challenge 52: Calculate Fibonacci(500) JavaScript function calculateFibonacci(n) { let a = BigInt(0); let b = BigInt(1); for (let i = 2; i <= n; i++) { [a, b] = [b, a + b]; } return b.toString(); } let result = calculateFibonacci(500); console.log(result); Challenge 53: Calculate 70! with High Precision JavaScript function calculateFactorial(n) { let result = BigInt(1); for (let i = 2; i <= n; i++) { result *= BigInt(i); } return result.toString(); } let factorial70 = calculateFactorial(70); console.log(factorial70); ConclusionBy completing these coding challenges, you'll strengthen your programming skills and gain the confidence needed to tackle more complex problems. Keep practicing, and soon you'll be well on your way to becoming a proficient coder. Comment More infoAdvertise with us R rohitshapcxa Follow Improve Article Tags : Geeks Premier League DSA Programming Geeks Premier League 2023 GFG-Practice +1 More Similar Reads Basics & PrerequisitesLogic Building ProblemsLogic building is about creating clear, step-by-step methods to solve problems using simple rules and principles. Itâs the heart of coding, enabling programmers to think, reason, and arrive at smart solutions just like we do.Here are some tips for improving your programming logic: Understand the pro 2 min read Analysis of AlgorithmsAnalysis of Algorithms is a fundamental aspect of computer science that involves evaluating performance of algorithms and programs. Efficiency is measured in terms of time and space.BasicsWhy is Analysis Important?Order of GrowthAsymptotic Analysis Worst, Average and Best Cases Asymptotic NotationsB 1 min read Data StructuresArray Data StructureIn this article, we introduce array, implementation in different popular languages, its basic operations and commonly seen problems / interview questions. An array stores items (in case of C/C++ and Java Primitive Arrays) or their references (in case of Python, JS, Java Non-Primitive) at contiguous 3 min read String in Data StructureA string is a sequence of characters. The following facts make string an interesting data structure.Small set of elements. Unlike normal array, strings typically have smaller set of items. For example, lowercase English alphabet has only 26 characters. ASCII has only 256 characters.Strings are immut 2 min read Hashing in Data StructureHashing is a technique used in data structures that efficiently stores and retrieves data in a way that allows for quick access. Hashing involves mapping data to a specific index in a hash table (an array of items) using a hash function. It enables fast retrieval of information based on its key. The 2 min read Linked List Data StructureA linked list is a fundamental data structure in computer science. It mainly allows efficient insertion and deletion operations compared to arrays. Like arrays, it is also used to implement other data structures like stack, queue and deque. Hereâs the comparison of Linked List vs Arrays Linked List: 2 min read Stack Data StructureA Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). LIFO implies that the element that is inserted last, comes out first and FILO implies that the element that is inserted first 2 min read Queue Data StructureA Queue Data Structure is a fundamental concept in computer science used for storing and managing data in a specific order. It follows the principle of "First in, First out" (FIFO), where the first element added to the queue is the first one to be removed. It is used as a buffer in computer systems 2 min read Tree Data StructureTree Data Structure is a non-linear data structure in which a collection of elements known as nodes are connected to each other via edges such that there exists exactly one path between any two nodes. Types of TreeBinary Tree : Every node has at most two childrenTernary Tree : Every node has at most 4 min read Graph Data StructureGraph Data Structure is a collection of nodes connected by edges. It's used to represent relationships between different entities. If you are looking for topic-wise list of problems on different topics like DFS, BFS, Topological Sort, Shortest Path, etc., please refer to Graph Algorithms. Basics of 3 min read Trie Data StructureThe Trie data structure is a tree-like structure used for storing a dynamic set of strings. It allows for efficient retrieval and storage of keys, making it highly effective in handling large datasets. Trie supports operations such as insertion, search, deletion of keys, and prefix searches. In this 15+ min read AlgorithmsSearching AlgorithmsSearching algorithms are essential tools in computer science used to locate specific items within a collection of data. In this tutorial, we are mainly going to focus upon searching in an array. When we search an item in an array, there are two most common algorithms used based on the type of input 2 min read Sorting AlgorithmsA Sorting Algorithm is used to rearrange a given array or list of elements in an order. For example, a given array [10, 20, 5, 2] becomes [2, 5, 10, 20] after sorting in increasing order and becomes [20, 10, 5, 2] after sorting in decreasing order. There exist different sorting algorithms for differ 3 min read Introduction to RecursionThe process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. A recursive algorithm takes one step toward solution and then recursively call itself to further move. The algorithm stops once we reach the solution 14 min read Greedy AlgorithmsGreedy algorithms are a class of algorithms that make locally optimal choices at each step with the hope of finding a global optimum solution. At every step of the algorithm, we make a choice that looks the best at the moment. To make the choice, we sometimes sort the array so that we can always get 3 min read Graph AlgorithmsGraph is a non-linear data structure like tree data structure. The limitation of tree is, it can only represent hierarchical data. For situations where nodes or vertices are randomly connected with each other other, we use Graph. Example situations where we use graph data structure are, a social net 3 min read Dynamic Programming or DPDynamic Programming is an algorithmic technique with the following properties.It is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of 3 min read Bitwise AlgorithmsBitwise algorithms in Data Structures and Algorithms (DSA) involve manipulating individual bits of binary representations of numbers to perform operations efficiently. These algorithms utilize bitwise operators like AND, OR, XOR, NOT, Left Shift, and Right Shift.BasicsIntroduction to Bitwise Algorit 4 min read AdvancedSegment TreeSegment Tree is a data structure that allows efficient querying and updating of intervals or segments of an array. It is particularly useful for problems involving range queries, such as finding the sum, minimum, maximum, or any other operation over a specific range of elements in an array. The tree 3 min read Pattern SearchingPattern searching algorithms are essential tools in computer science and data processing. These algorithms are designed to efficiently find a particular pattern within a larger set of data. Patten SearchingImportant Pattern Searching Algorithms:Naive String Matching : A Simple Algorithm that works i 2 min read GeometryGeometry is a branch of mathematics that studies the properties, measurements, and relationships of points, lines, angles, surfaces, and solids. From basic lines and angles to complex structures, it helps us understand the world around us.Geometry for Students and BeginnersThis section covers key br 2 min read Interview PreparationInterview Corner: All Resources To Crack Any Tech InterviewThis article serves as your one-stop guide to interview preparation, designed to help you succeed across different experience levels and company expectations. Here is what you should expect in a Tech Interview, please remember the following points:Tech Interview Preparation does not have any fixed s 3 min read GfG160 - 160 Days of Problem SolvingAre you preparing for technical interviews and would like to be well-structured to improve your problem-solving skills? Well, we have good news for you! GeeksforGeeks proudly presents GfG160, a 160-day coding challenge starting on 15th November 2024. In this event, we will provide daily coding probl 3 min read Practice ProblemGeeksforGeeks Practice - Leading Online Coding PlatformGeeksforGeeks Practice is an online coding platform designed to help developers and students practice coding online and sharpen their programming skills with the following features. GfG 160: This consists of most popular interview problems organized topic wise and difficulty with with well written e 6 min read Problem of The Day - Develop the Habit of CodingDo you find it difficult to develop a habit of Coding? If yes, then we have a most effective solution for you - all you geeks need to do is solve one programming problem each day without any break, and BOOM, the results will surprise you! Let us tell you how:Suppose you commit to improve yourself an 5 min read Like