{"id":92992,"date":"2025-11-10T12:14:44","date_gmt":"2025-11-10T06:44:44","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=92992"},"modified":"2026-09-02T20:00:06","modified_gmt":"2026-09-02T14:30:06","slug":"basic-coding-problems-in-dsa","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/basic-coding-problems-in-dsa\/","title":{"rendered":"Coding Problems in DSA: A Beginner&#8217;s Guide to Practice and Solutions (2026)"},"content":{"rendered":"\n<p>Coding Problems in DSA are questions built around arrays, linked lists, recursion, and sorting that test whether you can actually apply what you&#8217;ve learned, not just recite it. Each one forces you to break a bigger challenge into smaller steps and figure out the most efficient way to solve it.<\/p>\n\n\n\n<p>If you&#8217;re just starting out, don&#8217;t jump into the hardest problems you find online. Pick easy ones, solve them slowly, and understand why the solution works before moving to the next. Over time, this habit builds the kind of thinking that makes tougher problems feel far less intimidating.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>TL;DR Summary<\/strong><\/h2>\n\n\n\n<ul>\n<li>This guide breaks down 15 essential Coding Problems in DSA, covering everything from loops and arrays to recursion and linked lists.<\/li>\n\n\n\n<li>Each problem is explained in plain terms, so you understand the logic before jumping into code.<\/li>\n\n\n\n<li>A quick reference table lists every problem along with its category, difficulty level, and the core concept it teaches.<\/li>\n\n\n\n<li>The Coding Problems in DSA are grouped by topic, making it easy to focus on one area at a time, like sorting, searching, or patterns.<\/li>\n\n\n\n<li>By the end, you&#8217;ll have a clear starting point for practicing Coding Problems in DSA and building real problem-solving skills.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Key Concepts to Master for Solving DSA Problems<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/01@2x-1-2-1200x630.png\" alt=\"\" class=\"wp-image-97092\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/01@2x-1-2-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/01@2x-1-2-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/01@2x-1-2-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/01@2x-1-2-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/01@2x-1-2-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/12\/01@2x-1-2-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>Before indulging in solving<a href=\"https:\/\/www.guvi.in\/blog\/what-are-data-structures-and-algorithms\/\" target=\"_blank\" rel=\"noreferrer noopener\"> <strong>DSA<\/strong><\/a> problems, you need a solid understanding of essential topics. Start by gaining a firm grasp of input and output programs and, simultaneously, practice questions on<a href=\"https:\/\/www.guvi.in\/blog\/loops-in-javascript-with-examples\/\" target=\"_blank\" rel=\"noreferrer noopener\"> loops<\/a> and conditional statements to develop a fundamental understanding of how the logic flows during program execution.&nbsp;<\/p>\n\n\n\n<p>Then move on to array and<a href=\"https:\/\/www.guvi.in\/blog\/what-is-string-dsa-in-javascript\/\" target=\"_blank\" rel=\"noreferrer noopener\"> string<\/a> problems, which will help you handle and manage data efficiently. After that, you should explore basic search and sorting methods, such as linear search and bubble sort.<\/p>\n\n\n\n<p>Once you&#8217;ve completed all this, try tackling simple<a href=\"https:\/\/www.guvi.in\/blog\/recursion-algorithms-in-dsa\/\" target=\"_blank\" rel=\"noreferrer noopener\"> recursion<\/a> problems and<a href=\"https:\/\/www.guvi.in\/blog\/star-patterns-in-java-for-your-next-interview\/\" target=\"_blank\" rel=\"noreferrer noopener\"> pattern-based<\/a> printing to strengthen your analytical thinking. <\/p>\n\n\n\n<p>As you progress, start learning other data structures, such as stacks, queues, and linked lists, as well as math-based topics like numbers, factorials, and palindromes. These are key concepts to master for solving DSA problems.<\/p>\n\n\n\n<p><strong>Note: <\/strong>We use JavaScript<strong> <\/strong>as the primary language to explore the following fundamental DSA problems. <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">You can also use other programming languages, such as&nbsp;<a href=\"https:\/\/www.guvi.in\/hub\/cpp\/\" target=\"_blank\" rel=\"noopener\">C++<\/a>, Java, or&nbsp;<a href=\"https:\/\/www.guvi.in\/hub\/python\/\" target=\"_blank\" rel=\"noopener\">Python<\/a>&nbsp;<em>(the logic is the same across&nbsp;<\/em><\/span><em>languages; only the syntax differs)<\/em>.<\/p>\n\n\n\n<p><strong><em>Strengthen your programming skills with our comprehensive and affordable HCL GUVI&#8217;s DSA course<\/em>: <\/strong><a href=\"https:\/\/www.guvi.in\/courses\/bundles\/dsa-for-programmers\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=basic-coding-problems-in-dsa\" target=\"_blank\" rel=\"noreferrer noopener\">DSA for Programmers Course<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong><em>Ready to build real projects? The HCL GUVI&#8217;s <\/em><\/strong><em><a href=\"https:\/\/www.guvi.in\/zen-class\/full-stack-development-course\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=basic-coding-problems-in-dsa\" target=\"_blank\" rel=\"noreferrer noopener\">Software and AI Engineer Course<\/a><\/em><strong><em> teaches DSA, full stack development, and AI-powered workflows through hands-on projects, expert mentorship, and mock interviews, everything you need to turn practice problems into a job-ready portfolio. Enroll now and start building.<\/em><\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>List of Basic Coding Problems in DSA for Beginners<\/strong><\/h2>\n\n\n\n<p>The following are the fundamental coding problems in DSA we have mentioned, along with the category to which each belongs:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Print all prime numbers within a given range <em>(Loops and Conditionals)<\/em><\/strong><\/h3>\n\n\n\n<p>Check every number in the range and print only the ones that can&#8217;t be divided evenly by anything except 1 and themselves.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function PrimesInRange(start, end) {\n\n  for (let num = start; num &lt;= end; num++) {\n\n    let isPrime = true;\n\n    if (num &lt; 2) continue;         \/\/ 0 and 1 are not prime\n\n    for (let i = 2; i * i &lt;= num; i++) {\n\n      if (num % i === 0) {        \n\n        isPrime = false;\n\n        break;\n\n      }\n\n    }\n\n    if (isPrime) {\n\n      console.log(num);\n\n    }\n\n  }\n\n}\n\nPrimesInRange(10, 30);<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>11\n\n13\n\n17\n\n19\n\n23\n\n29<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>In this code, the function traverses every number in the given range sequentially to check whether it is <strong>divisible by any number from 2<\/strong> to its square root. <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\"><strong>If a given input number has no divisors<\/strong>, it is considered prime\u00a0<\/span>and printed to the console; otherwise, the loop exits, terminating the operation.<\/p>\n\n\n\n<p><strong>Explore:<\/strong> <a href=\"https:\/\/www.guvi.in\/blog\/can-you-get-a-developer-job-without-dsa\/\" target=\"_blank\" rel=\"noreferrer noopener\">Can I Get a Developer Job Without DSA? The Truth From 50+ Hired Developers<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Find the sum of digits of a number <em>(Loops and Conditionals)<\/em><\/strong><\/h3>\n\n\n\n<p>Break the number into individual digits and add them all together.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function sumTotalOfDigits(num) {\n\n  let sum = 0;\n\n  while (num &gt; 0) {\n\n    let digit = num % 10;        \/\/ extract last digit\n\n    sum += digit;               \/\/ add it to sum\n\n    num = Math.floor(num \/ 10);        \/\/ remove last digit\n\n  }\n\n  console.log(sum);\n\n}\n\nsumTotalOfDigits(9876);<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>30<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>Observe the modulus operator <strong>% 10<\/strong> here; it is included in this code to repeatedly extract the last digit of a number and add it back to a sum variable (which in this case is <strong>initialized to 0<\/strong>).&nbsp;<\/p>\n\n\n\n<p>Once that is done, we move on to the next line, where we remove the last digit by <strong>dividing by 10<\/strong>, then use a built-in Math method to round it down to the nearest integer. This process continues <strong>until the number becomes 0<\/strong>. And at last, we get our resultant sum of all digits.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Find the second largest element in an array <em>(Arrays and Strings)<\/em><\/strong><\/h3>\n\n\n\n<p>Go through the array once and keep track of the largest and second largest values as you compare each element.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function secondLargestNumber(arr) {\n\n  if (arr.length &lt; 2) {\n\n    console.log(\u201cInvalid, number should contain at least 2 digit.\u201d);\n\n    return;\n\n  }\n\n  let firstNum = -Infinity;\n\n  let secondNum = -Infinity;\n\n  for (let num of arr) {\n\n    if (num &gt; firstNum) {\n\n      second = firstNum;\n\n      firstNum = num;\n\n    } else if (num &gt; secondNum &amp;&amp; num &lt; firstNum) {\n\n      secondNum = num;\n\n    }\n\n  }\n\n  console.log(secondNum);\n\n}\n\nsecondLargestNumber(&#91;10, 40, 30, 50, 20]);<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>40<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>Here, the<strong> &#8216;for of&#8217; <\/strong>loop is used to traverse through each element in the <strong><a href=\"https:\/\/en.wikipedia.org\/wiki\/Array_(data_structure)\" target=\"_blank\" rel=\"noopener\">array<\/a><\/strong> to keep track of the largest and second most significant numbers. <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">The&nbsp;<strong>logic flows like this:<\/strong>&nbsp;if an<\/span><strong> element is larger than the current largest number<\/strong> in the array, <strong>it updates both<\/strong> the largest and the second-largest numbers.<\/p>\n\n\n\n<p><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">If it&#8217;s<strong>&nbsp;between the largest and the second-largest<\/strong>, it<strong>&nbsp;updates only&nbsp;<\/strong><\/span>the second-largest. This way, the function effectively finds the second-largest element without unnecessary steps.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Reverse a string without using built-in functions <em>(Arrays and Strings)<\/em><\/strong><\/h3>\n\n\n\n<p>Swap characters from the start and end of the string, moving toward the middle, until the whole string is flipped.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function reverseString(str) {\n\n  let result = \u201c\u201d;\n\n  for (let i = str.length \u2013 1; i &gt;= 0; i\u2013) {\n\n    result += str&#91;i];\n\n  }\n\n  console.log(result);\n\n}\n\nreverseString(\u201chello\u201d);<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>olleh<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>In this example, we run the <strong>for loop<\/strong> <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">starting from the&nbsp;<strong>last character of the string<\/strong>, so we can iterate<strong>&nbsp;backwards<\/strong>&nbsp;and build a new&nbsp;<\/span>string by<strong> adding each character in reverse order<\/strong>. This function traverses the string from end to start and appends each character, producing the reversed string as output.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Implement Linear Search <em>(Searching)<\/em><\/strong><\/h3>\n\n\n\n<p>Check each element one by one until you find the value you&#8217;re looking for.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function linearSearchOperation(arr, target) {\n\n  for (let i = 0; i &lt; arr.length; i++) {\n\n    if (arr&#91;i] === target) {\n\n      console.log(`Element ${arr&#91;i]} found at index ${i}`);\n\n      return;\n\n    }\n\n  }\n\n  console.log(\u201cElement doesn\u2019t exist.\u201d);\n\n}\n\nlinearSearchOperation(&#91;5, 8, 2, 9, 1], 9);\n\n\/\/and\n\nlinearSearchOperation(&#91;5, 8, 2, 9, 1], 4);<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Element 9 found at index 3\n\nElement doesn\u2019t exist.   \/\/ 4 is not present in the array<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>The search operation begins by checking each element of the<a href=\"https:\/\/www.guvi.in\/blog\/guide-for-arrays-in-javascript\/\" target=\"_blank\" rel=\"noreferrer noopener\"> <strong>array<\/strong><\/a> in sequence to determine <strong>whether any matches the target value<\/strong>. <strong>If a match is found<\/strong>, it prints the corresponding element along with its index. And if the <strong>loop completes without finding the target element<\/strong>, it prints that the number doesn&#8217;t exist.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Implement Binary Search on a sorted array <em>(Searching)<\/em><\/strong><\/h3>\n\n\n\n<p>Repeatedly divide the sorted array in half to quickly narrow down where the value is.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function binarySearchOperation(arr, target) {\n\n  let left = 0;\n\n  let right = arr.length \u2013 1;\n\n  while (left &lt;= right) {\n\n    let mid = Math.floor((left + right) \/ 2);\n\n    if (arr&#91;mid] === target) {\n\n      console.log(`Element ${arr&#91;mid]} found at index ${mid}`);\n\n      return;\n\n    }\n\n    else if (arr&#91;mid] &lt; target) {\n\n      left = mid + 1;\n\n    }\n\n    else {\n\n      right = mid \u2013 1;\n\n    }\n\n  }\n\n  console.log(\u201cElement not found inside the given array.\u201d);\n\n}\n\nbinarySearchOperation(&#91;2, 5, 8, 12, 16, 23, 38, 56], 23);<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Element 23 found at index 5<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>Binary search is an algorithm that<a href=\"https:\/\/www.guvi.in\/blog\/divide-and-conquer-algorithm\/\" target=\"_blank\" rel=\"noreferrer noopener\"> <strong>divides<\/strong><\/a><strong> a sorted array in half to check whether the element matches the target value; this process repeats<\/strong> until the element is found or the array length becomes 1, indicating there is no more space left to search.&nbsp;<\/p>\n\n\n\n<p><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\"><strong>If the target is smaller than the middle&nbsp;<\/strong><\/span><strong>element<\/strong>, it continues <strong>searching in the left half<\/strong>; <strong>if it is larger, it searches in the right half<\/strong>. And in this way, the search process becomes much faster than the linear search for sorted arrays, because in each loop, we <strong>traverse only half the previous array size<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7. Sort an array using Bubble Sort <em>(Sorting)<\/em><\/strong><\/h3>\n\n\n\n<p>Compare pairs of neighboring elements and swap them if they&#8217;re in the wrong order, repeating until the array is sorted.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function bubbleSortingNumbers(arr) {\n\n  let n = arr.length;\n\n  for (let i = 0; i &lt; n \u2013 1; i++) {\n\n    for (let j = 0; j &lt; n \u2013 i \u2013 1; j++) {\n\n      if (arr&#91;j] &gt; arr&#91;j + 1]) {\n\n        \/\/ swapping elements with each other\n\n        let temp = arr&#91;j];\n\n        arr&#91;j] = arr&#91;j + 1];\n\n        arr&#91;j + 1] = temp;\n\n      }\n\n    }\n\n  }\n\n  console.log(\u201cResultant array in sorted order:\u201d, arr);\n\n}\n\nbubbleSortingNumbers(&#91;64, 34, 25, 12, 22, 11, 90]);<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Resultant array in sorted order: &#91;11, 12, 22, 25, 34, 64, 90]<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>In this code, the function <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">sorts the<a href=\"https:\/\/www.guvi.in\/blog\/sorting-in-data-structure-categories-types\/\" target=\"_blank\" rel=\"noopener\">&nbsp;<\/a><a href=\"https:\/\/www.guvi.in\/blog\/sorting-in-data-structure-categories-types\/\" target=\"_blank\" rel=\"noopener\"><strong>array<\/strong><\/a>&nbsp;by&nbsp;<strong>repeatedly comparing adjacent&nbsp;<\/strong><\/span><strong>elements <\/strong>and <strong>swapping<\/strong> them if they are out of order. With every single loop execution, the biggest unsorted element bubbles up to the end of the array. And after completion of all loop runs, the input arrays get sorted in ascending order.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>8. Sort an array using Insertion Sort <em>(Sorting)<\/em><\/strong><\/h3>\n\n\n\n<p>Take each element and insert it into its correct position among the already sorted elements before it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function insertionSorting(arr) {\n\n  for (let i = 1; i &lt; arr.length; i++) {\n\n\n    let key = arr&#91;i];\n\n    let j = i \u2013 1;\n\n\/\/ Move the elements that are greater than the key element one position ahead\n\n    while (j &gt;= 0 &amp;&amp; arr&#91;j] &gt; key) {\n\n      arr&#91;j + 1] = arr&#91;j];\n\n      j\u2013;\n\n    }\n\n    arr&#91;j + 1] = key;\n\n  }\n\n  console.log(\u201cResultant array in sorted order\u201d, arr);\n\n}\n\ninsertionSorting(&#91;12, 11, 13, 5, 6]);<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Resultant array in sorted order: &#91;5, 6, 11, 12, 13]<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>In this example, the function begins by treating an <strong>element as a key<\/strong> and <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">placing it in the&nbsp;<strong>correct position among the already sorted<\/strong><\/span><strong> elements on the left<\/strong>. It <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">does this by gradually<strong>&nbsp;shifting all larger array elements to the right&nbsp;<\/strong>to make<\/span> space for the key element. After repeating this process for every element, the input array gets sorted and printed to the console.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>9. Find the factorial of a number using recursion <em>(Basic Math and Number Problem)<\/em><\/strong><\/h3>\n\n\n\n<p>Multiply the number by the factorial of the number just below it, repeating until you reach 1.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function findFactorial(n) {\n\n  let result = 1;\n\n  for (let i = 1; i &lt;= n; i++) {\n\n    result *= i;\n\n  }\n\n  console.log(result);\n\n}\n\nfindFactorial(6);<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>720<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>A factorial is the product of all the positive integers less than the given number, including itself. Here, we have calculated the factorial by multiplying the result variable by each number<strong> from 1 to the n parameter using a loop<\/strong>. After the loop completes, the result stores the final product value, which is printed to the console.<\/p>\n\n\n\n<p><strong><em>Also read:<\/em><\/strong><a href=\"https:\/\/www.guvi.in\/blog\/guide-on-maths-for-dsa\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong> Maths for DSA: What Most Beginners Get Wrong<\/strong><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>10. Print the Fibonacci series using recursion <em>(Recursion)<\/em><\/strong><\/h3>\n\n\n\n<p>Each number in the series is generated by adding the two numbers that came right before it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function fibonacciRecursive(n) {\n\n  if (n === 0) return 0;\n\n  if (n === 1) return 1;\n\n  return fibonacciRecursive(n \u2013 1) + fibonacciRecursive(n \u2013 2);\n\n}<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0\n\n1\n\n1\n\n2\n\n3\n\n5\n\n8<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>This recursive Fibonacci function finds the nth Fibonacci number by checking <strong>if n is 0 or 1 (base cases) and returning 0 or 1 accordingly<\/strong>. For other values, it calls itself to calculate the <strong>previous two Fibonacci numbers<\/strong> and <strong>adds them,<\/strong> building the sequence recursively.  <\/p>\n\n\n\n<p><strong><em>Also read:<\/em><\/strong><a href=\"https:\/\/www.guvi.in\/blog\/guide-for-recursion-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong> Mastering Recursion in Python: A Comprehensive Guide<\/strong><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>11. Print a pyramid star pattern <em>(Patterns)<\/em><\/strong><\/h3>\n\n\n\n<p>Print stars in increasing numbers on each line to form a pyramid shape.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function pyramidStarPattern(rows) {\n\n  for (let i = 1; i &lt;= rows; i++) {\n\n    let figure = \u201c\u201d;\n\n    \/\/ print the spaces\n\n    for (let j = 1; j &lt;= rows \u2013 i; j++) {\n\n      figure += \u201d \u201c;\n\n    }\n\n    \/\/ print the stars\n\n    for (let k = 1; k &lt;= 2 * i \u2013 1; k++) {\n\n      figure += \u201c*\u201d;\n\n    }\n\n    console.log(figure);\n\n  }\n\n}\n\npyramidStarPattern(5);<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    *\n\n   ***\n\n  *****\n\n *******\n\n*********<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>The code prints a pyramid shape by <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">first adding spaces<strong>&nbsp;to align the stars,<\/strong><\/span> then <strong>printing stars for each row<\/strong>. Each subsequent row has two more stars than the previous one, forming a <strong>symmetrical pyramid<\/strong>. The spaces ensure the stars are <strong>properly centered<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>12. Print a number triangle pattern <em>(Patterns)<\/em><\/strong><\/h3>\n\n\n\n<p>Print numbers in a specific order on each line to build a triangle shape.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function numberTrianglePattern(rows) {\n\n  for (let i = 1; i &lt;= rows; i++) {\n\n    let num = \u201c\u201d;\n\n    for (let j = 1; j &lt;= i; j++) {\n\n      num += j + \u201d \u201c;\n\n    }\n\n    console.log(num);\n\n  }\n\n}\n\nnumberTrianglePattern(5);<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\n\n1 2\n\n1 2 3\n\n1 2 3 4\n\n1 2 3 4 5<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>The code prints a triangular pattern of numbers. Each row contains numbers from 1 up to the current row number. With each new row, one more number is added, creating a<strong> growing triangle of numbers <\/strong>in the output.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>13. Insert a node at the end of a linked list <em>(Linked List)<\/em><\/strong><\/h3>\n\n\n\n<p>Walk through the list until you reach the last node, then attach the new node right after it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Node {\n\n&nbsp;&nbsp;constructor(data) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;this.data = data;\n\n&nbsp;&nbsp;&nbsp;&nbsp;this.next = null;\n\n&nbsp;&nbsp;}\n\n}\n\nclass LinkedList {\n\n&nbsp;&nbsp;constructor() {\n\n&nbsp;&nbsp;&nbsp;&nbsp;this.head = null;\n\n&nbsp;&nbsp;}\n\n&nbsp;&nbsp;insertAtEnd(data) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;let newNode = new Node(data);\n\n&nbsp;&nbsp;&nbsp;&nbsp;if (this.head === null) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.head = newNode;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;let current = this.head;\n\n&nbsp;&nbsp;&nbsp;&nbsp;while (current.next !== null) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;current = current.next;\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;current.next = newNode;\n\n&nbsp;&nbsp;}\n\n&nbsp;&nbsp;printList() {\n\n&nbsp;&nbsp;&nbsp;&nbsp;let current = this.head;\n\n&nbsp;&nbsp;&nbsp;&nbsp;let figure = \"\";\n\n&nbsp;&nbsp;&nbsp;&nbsp;while (current !== null) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;figure += current.data + \" -&gt; \";\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;current = current.next;\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;figure += \"null\";\n\n&nbsp;&nbsp;&nbsp;&nbsp;console.log(figure);\n\n&nbsp;&nbsp;}\n\n}\n\nlet list = new LinkedList();\n\nlist.insertAtEnd(10);\n\nlist.insertAtEnd(20);\n\nlist.insertAtEnd(30);\n\nlist.printList();<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>10 -&gt; 20 -&gt; 30 -&gt; null<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>The code <strong>creates a new node and adds it to the end of the<\/strong><a href=\"https:\/\/www.guvi.in\/blog\/linked-list-in-data-structure\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong> linked list<\/strong><\/a>. If the list is empty, the <strong>new node becomes the head<\/strong>. Otherwise,<strong> it traverses the list until the last node and links the new node there<\/strong>. This way, elements are added sequentially to the end of the list.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>14. Implement push and pop operations in a stack <em>(Stack)<\/em><\/strong><\/h3>\n\n\n\n<p>Push adds a new item to the top of the stack, and pop removes the item that&#8217;s currently on top.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Stack {\n\n  constructor() {\n\n    this.items = &#91;];\n\n  }\n\n  push(element) {\n\n    this.items.push(element);\n\n  }\n\n  pop() {\n\n    if (this.items.length === 0) {\n\n      console.log(\u201cStack is empty, no items\u201d);\n\n      return;\n\n    }\n\n    console.log(\u201cPopped Item:\u201d, this.items.pop());\n\n  }\n\n  printStack() {\n\n    console.log(\u201cStack:\u201d, this.items.join(\u201d -&gt; \u201c));\n\n  }\n\n}\n\nlet stack = new Stack();\n\nstack.push(10);\n\nstack.push(20);\n\nstack.push(30);\n\nstack.printStack();\n\nstack.pop();\n\nstack.printStack();<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Stack: 10 -&gt; 20 -&gt; 30\n\nPopped Item: 30\n\nStack: 10 -&gt; 20<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>The code uses an array to represent a <strong><a href=\"https:\/\/www.guvi.in\/blog\/what-is-a-stack\/\" target=\"_blank\" rel=\"noreferrer noopener\">stack<\/a><\/strong>. The <strong>push function<\/strong> adds an element to the end of the array, while the<strong> pop function <\/strong>removes the last element. This follows the <strong>Last In First Out (LIFO) principle<\/strong>, where the most recently added element is the first one to be removed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>15. Check if a number is a palindrome <em>(Basic Math and Number Problems)<\/em><\/strong><\/h3>\n\n\n\n<p>Reverse the number and check if it matches the original number.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function isPalindrome(num) {\n\n  let originalNum = num;\n\n  let reversedNum = 0;\n\n  while (num &gt; 0) {\n\n    let digit = num % 10;\n\n    reversedNum = reversedNum * 10 + digit;\n\n    num = Math.floor(num \/ 10);\n\n  }\n\n  if (originalNum === reversedNum) {\n\n    console.log(`${original} is a palindrome number`);\n\n  } else {\n\n    console.log(`${original} is not a palindrome number`);\n\n  }\n\n}\n\nisPalindrome(363);\n\nisPalindrome(198);<\/code><\/pre>\n\n\n\n<p><strong><em>Output:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>363 is a palindrome number\n\n198 is not a palindrome number<\/code><\/pre>\n\n\n\n<p><strong><em>Explanation:<\/em><\/strong><\/p>\n\n\n\n<p>The code checks if a number is the <strong>same forwards and backwards<\/strong>. It <strong>reverses the number by extracting the last digit repeatedly <\/strong>and building a <strong>new reversed number<\/strong>. Finally, <strong>it compares the reversed number with the original<\/strong>. If they are equal, the number is a palindrome; otherwise, it is not.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Coding Problems in DSA: Quick Reference Table<\/strong><\/h2>\n\n\n\n<p><span style=\"font-size: revert; color: initial;\">Below is a categorized breakdown of the Coding Problems in DSA covered here, along with their difficulty and core concept<\/span>:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><strong>Problem Name<\/strong><\/th><th><strong>Category<\/strong><\/th><th><strong>Difficulty Level<\/strong><\/th><th><strong>Concept Used<\/strong><\/th><\/tr><\/thead><tbody><tr><td><strong>Prime Numbers in a Range<\/strong><\/td><td>Loops and Conditionals<\/td><td>Easy<\/td><td>Loop and Divisibility Check<\/td><\/tr><tr><td><strong>Sum of Digits<\/strong><\/td><td>Loops and Conditionals<\/td><td>Easy<\/td><td>Modulus and Division<\/td><\/tr><tr><td><strong>Second Largest Element in an Array<\/strong><\/td><td>Arrays and Strings<\/td><td>Easy<\/td><td>Single Pass Comparison<\/td><\/tr><tr><td><strong>Reverse a String<\/strong><\/td><td>Arrays and Strings<\/td><td>Easy<\/td><td>Two Pointer Swapping<\/td><\/tr><tr><td><strong>Linear Search<\/strong><\/td><td>Searching<\/td><td>Easy<\/td><td>Sequential Comparison<\/td><\/tr><tr><td><strong>Binary Search<\/strong><\/td><td>Searching<\/td><td>Easy<\/td><td>Divide and Conquer<\/td><\/tr><tr><td><strong>Bubble Sort<\/strong><\/td><td>Sorting<\/td><td>Easy<\/td><td>Swapping and Comparison<\/td><\/tr><tr><td><strong>Insertion Sort<\/strong><\/td><td>Sorting<\/td><td>Easy<\/td><td>Shifting and Insertion<\/td><\/tr><tr><td><strong>Factorial Using Recursion<\/strong><\/td><td>Basic Math and Number Problems<\/td><td>Easy<\/td><td>Recursion<\/td><\/tr><tr><td><strong>Fibonacci Series Using Recursion<\/strong><\/td><td>Recursion<\/td><td>Medium<\/td><td>Recursion<\/td><\/tr><tr><td><strong>Pyramid Star Pattern<\/strong><\/td><td>Patterns<\/td><td>Easy<\/td><td>Nested Loops<\/td><\/tr><tr><td><strong>Number Triangle Pattern<\/strong><\/td><td>Patterns<\/td><td>Easy<\/td><td>Nested Loops<\/td><\/tr><tr><td><strong>Insert Node at End of Linked List<\/strong><\/td><td>Linked List<\/td><td>Medium<\/td><td>Pointer Traversal<\/td><\/tr><tr><td><strong>Push and Pop in a Stack<\/strong><\/td><td>Stack<\/td><td>Easy<\/td><td>LIFO (Last In First Out)<\/td><\/tr><tr><td><strong>Palindrome Number Check<\/strong><\/td><td>Basic Math and Number Problems<\/td><td>Easy<\/td><td>Number Reversal<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>Practicing Coding Problems in DSA regularly builds the kind of logical thinking that carries over into real projects and interviews. Starting with simple patterns, loops, and searches lays the groundwork for tackling recursion, linked lists, and sorting with more clarity. Each problem you solve adds a small piece to the bigger picture of how code actually works.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>FAQs<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1788356941539\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">1. How many Coding Problems in DSA should a beginner solve daily?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>One or two a day is enough. Consistency and problem quality matter more than speed.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788356942172\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">2. Which topic should I start with first?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Loops and arrays. They&#8217;re the easiest entry point into Coding Problems in DSA.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788356943748\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">3. Do I need a specific programming language to solve these?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>No. The logic behind Coding Problems in DSA stays the same across languages, but Python or JavaScript are good ones to start with.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788356944870\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">4. Are these problems enough for interview preparation?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>They&#8217;re a good start, but interview-level Coding Problems in DSA go deeper into optimization.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788357134489\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">5. What&#8217;s the best way to practice these problems?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Write the logic on paper first, then code it. Don&#8217;t jump straight to solutions.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Coding Problems in DSA are questions built around arrays, linked lists, recursion, and sorting that test whether you can actually apply what you&#8217;ve learned, not just recite it. Each one forces you to break a bigger challenge into smaller steps and figure out the most efficient way to solve it. If you&#8217;re just starting out, [&hellip;]<\/p>\n","protected":false},"author":64,"featured_media":97091,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"views":"4261","authorinfo":{"name":"Abhishek Pati","url":"https:\/\/www.guvi.in\/blog\/author\/abhishek-pati\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/11\/Feature-image-7-300x116.png","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/92992"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/64"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=92992"}],"version-history":[{"count":22,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/92992\/revisions"}],"predecessor-version":[{"id":136793,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/92992\/revisions\/136793"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/97091"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=92992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=92992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=92992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}