{"id":25834497,"url":"https://github.com/codewitheshayoutube/dsa","last_synced_at":"2025-10-07T03:10:09.793Z","repository":{"id":261821184,"uuid":"885447076","full_name":"codewithEshaYoutube/DSA","owner":"codewithEshaYoutube","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-08T15:57:05.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-08T16:42:32.959Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codewithEshaYoutube.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-08T15:48:56.000Z","updated_at":"2024-11-08T15:57:08.000Z","dependencies_parsed_at":"2024-11-08T16:44:52.162Z","dependency_job_id":null,"html_url":"https://github.com/codewithEshaYoutube/DSA","commit_stats":null,"previous_names":["codewitheshayoutube/dsa"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewithEshaYoutube%2FDSA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewithEshaYoutube%2FDSA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewithEshaYoutube%2FDSA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewithEshaYoutube%2FDSA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codewithEshaYoutube","download_url":"https://codeload.github.com/codewithEshaYoutube/DSA/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241300351,"owners_count":19940487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-01T00:58:29.470Z","updated_at":"2025-10-07T03:10:04.761Z","avatar_url":"https://github.com/codewithEshaYoutube.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DSA\n# Data Structures and Algorithms (DSA) Problems in JavaScript\n\nThis repository contains solutions to a variety of **Data Structures and Algorithms (DSA)** problems, all implemented in **JavaScript**. These problems cover a wide range of topics, from basic array manipulations to advanced tree and graph algorithms.\n\n## Table of Contents\n- [Array and String Problems](#array-and-string-problems)\n- [Linked List Problems](#linked-list-problems)\n- [Stack and Queue Problems](#stack-and-queue-problems)\n- [Tree Problems](#tree-problems)\n- [Sorting Algorithms](#sorting-algorithms)\n- [Graph Algorithms](#graph-algorithms)\n- [Mathematics and Number Theory](#mathematics-and-number-theory)\n- [Testing the Functions](#testing-the-functions)\n\n## Array and String Problems\n\n1. **Reverse an Array**\n    - Problem: Reverse the given array.\n    - Solution: A simple two-pointer approach to swap elements.\n    \n2. **Check if a String is a Palindrome**\n    - Problem: Check whether a string is a palindrome, considering only alphanumeric characters and ignoring case.\n    - Solution: Remove non-alphanumeric characters, convert to lowercase, and check if it matches the reversed string.\n\n3. **Rotate an Array by `k` Positions**\n    - Problem: Rotate the elements of an array to the right by `k` positions.\n    - Solution: Use array slicing to perform the rotation.\n\n---\n\n## Linked List Problems\n\n1. **Reverse a Singly Linked List**\n    - Problem: Reverse the given linked list.\n    - Solution: Use a three-pointer approach to reverse the list.\n\n2. **Detect Cycle in a Linked List (Floyd’s Tortoise and Hare)**\n    - Problem: Detect if there is a cycle in a linked list.\n    - Solution: Use two pointers, one moving twice as fast as the other, to detect the cycle.\n\n---\n\n## Stack and Queue Problems\n\n1. **Implement Stack Using Two Queues**\n    - Problem: Implement a stack using two queues.\n    - Solution: Use two queues and simulate the behavior of a stack.\n\n2. **Implement Queue Using Two Stacks**\n    - Problem: Implement a queue using two stacks.\n    - Solution: Use two stacks to simulate the behavior of a queue.\n\n---\n\n## Tree Problems\n\n1. **Inorder Traversal of a Binary Tree (Recursive)**\n    - Problem: Perform inorder traversal on a binary tree.\n    - Solution: Recursively visit the left subtree, the node, and then the right subtree.\n\n2. **Check if a Binary Tree is Balanced**\n    - Problem: Check if a binary tree is height-balanced.\n    - Solution: Calculate the height of each subtree and ensure the difference in height is at most 1.\n\n---\n\n## Sorting Algorithms\n\n1. **Merge Sort**\n    - Problem: Sort an array using merge sort algorithm.\n    - Solution: Recursively split the array and merge the sorted halves.\n\n2. **Quick Sort**\n    - Problem: Sort an array using quick sort algorithm.\n    - Solution: Use the divide-and-conquer approach, selecting a pivot and partitioning the array.\n\n---\n\n## Graph Algorithms\n\n1. **Depth First Search (DFS)**\n    - Problem: Traverse a graph using Depth First Search.\n    - Solution: Use recursion or a stack to explore each node and its neighbors.\n\n2. **Breadth First Search (BFS)**\n    - Problem: Traverse a graph using Breadth First Search.\n    - Solution: Use a queue to explore nodes level by level.\n\n---\n\n## Mathematics and Number Theory\n\n1. **Check if a Number is Prime**\n    - Problem: Check if a given number is prime.\n    - Solution: Check divisibility up to the square root of the number.\n\n2. **Calculate the Greatest Common Divisor (GCD)**\n    - Problem: Find the greatest common divisor of two numbers.\n    - Solution: Use the Euclidean algorithm to calculate GCD.\n\n3. **Sieve of Eratosthenes - Find All Primes Up to N**\n    - Problem: Find all prime numbers up to a given limit `n`.\n    - Solution: Implement the Sieve of Eratosthenes algorithm to mark non-prime numbers.\n\n---\n\n## Testing the Functions\n\nHere are a few tests you can run to validate the solutions:\n\n```javascript\n// Test Array and String Functions\nconsole.log(reverseArray([1, 2, 3, 4, 5])); // [5, 4, 3, 2, 1]\nconsole.log(isPalindrome(\"A man a plan a canal Panama\")); // true\nconsole.log(rotateArray([1, 2, 3, 4, 5], 2)); // [4, 5, 1, 2, 3]\n\n// Test Linked List Functions\nconst head = { val: 1, next: { val: 2, next: { val: 3, next: null } } };\nconsole.log(reverseLinkedList(head)); // 3 -\u003e 2 -\u003e 1\n\n// Test Sorting Functions\nconsole.log(mergeSort([3, 1, 4, 1, 5, 9, 2, 6])); // [1, 1, 2, 3, 4, 5, 6, 9]\nconsole.log(quickSort([3, 1, 4, 1, 5, 9, 2, 6])); // [1, 1, 2, 3, 4, 5, 6, 9]\n\n// Test Graph Algorithms\nconst graph = {\n    1: [2, 3],\n    2: [1, 4],\n    3: [1, 5],\n    4: [2],\n    5: [3]\n};\n\nconsole.log(dfs(graph, 1)); // Set { 1, 2, 3, 4, 5 }\nconsole.log(bfs(graph, 1)); // Set { 1, 2, 3, 4, 5 }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewitheshayoutube%2Fdsa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodewitheshayoutube%2Fdsa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewitheshayoutube%2Fdsa/lists"}