{"id":31039454,"url":"https://github.com/dheerajjha451/dsa_typescript","last_synced_at":"2025-09-14T07:57:47.972Z","repository":{"id":266029104,"uuid":"896468241","full_name":"Dheerajjha451/DSA_Typescript","owner":"Dheerajjha451","description":"Data Structures and Algorithms in TypeScript","archived":false,"fork":false,"pushed_at":"2024-12-18T10:30:05.000Z","size":75,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-29T04:18:26.715Z","etag":null,"topics":["datastructuresandalgorithm","dsa","dsa-algorithm","learn","typescript"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dheerajjha451.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-30T12:52:19.000Z","updated_at":"2025-04-07T15:53:46.000Z","dependencies_parsed_at":"2024-12-05T18:15:48.990Z","dependency_job_id":null,"html_url":"https://github.com/Dheerajjha451/DSA_Typescript","commit_stats":null,"previous_names":["dheerajjha451/dsa_typescript"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Dheerajjha451/DSA_Typescript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dheerajjha451%2FDSA_Typescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dheerajjha451%2FDSA_Typescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dheerajjha451%2FDSA_Typescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dheerajjha451%2FDSA_Typescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dheerajjha451","download_url":"https://codeload.github.com/Dheerajjha451/DSA_Typescript/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dheerajjha451%2FDSA_Typescript/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275076592,"owners_count":25401317,"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","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["datastructuresandalgorithm","dsa","dsa-algorithm","learn","typescript"],"created_at":"2025-09-14T07:57:46.557Z","updated_at":"2025-09-14T07:57:47.935Z","avatar_url":"https://github.com/Dheerajjha451.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"- Typescript\n    \n\n    \n    - Array\n        1. Reverse Array\n        \n        ```tsx\n        let arr=[1,2,3,4,5];\n        reverseArr(arr);\n        console.log(arr);\n        function reverseArr(arr:number[]){\n            let left=0;\n            let right=arr.length-1;\n            while(left\u003cright){\n                let temp=arr[left];\n                arr[left]=arr[right];\n                arr[right]=temp;\n                left++;\n                right--;\n            }\n        }\n        ```\n        \n        1. minMaxArray\n        \n        ```tsx\n        const arr=[1,3,4,6,7,5];\n        getMinMax(arr);\n        function getMinMax(arr:number[]){\n        let n=arr.length;\n        secondLargest(arr);\n        secondSmallest(arr);\n        }\n        function secondLargest(arr:number[]){\n            let largest=-Infinity;\n            let secondLargest=-Infinity;\n            for(let i=0;i\u003carr.length;i++){\n                if(arr[i]\u003elargest){\n                    secondLargest=largest;\n                    largest=arr[i];\n                }else if(arr[i]\u003e=secondLargest \u0026\u0026 arr[i]!=largest){\n                    secondLargest=arr[i];\n                }\n            }\n            console.log(\"largest\",largest);\n            console.log(\"secondLargest\",secondLargest);\n        \n        }\n        function secondSmallest(arr:number[]){\n            let smallest=Infinity;\n            let secondSmallest=Infinity;\n            for(let i=0;i\u003carr.length;i++){\n                if(arr[i]\u003carr[smallest]){\n                    secondSmallest=smallest;\n                    smallest=arr[i];\n                }else if(arr[i]\u003c=secondSmallest \u0026\u0026 arr[i]!=smallest){\n                    secondSmallest=arr[i];\n                }\n            }\n             console.log(\"smallest\", smallest);\n          console.log(\"second smallest\", secondSmallest);\n        }\n        ```\n        \n        1. Kth smallest\n        \n        ```tsx\n        let arr = [1, 2, 3, 29, 344, 23];\n        let k = 4;\n        kSmallest(arr, k);\n        \n        function kSmallest(arr: number[], k: number): void {\n            if (k \u003e 0 \u0026\u0026 k \u003c= arr.length) {\n                arr.sort((a, b) =\u003e a - b);\n                console.log(arr[k - 1]);\n            } else {\n                console.log(\"Invalid value of k\");\n            }\n        }\n        \n        ```\n        \n        1. Sort (0,1,2)\n        \n        ```tsx\n        let arr=[0,2,1,2,0];\n        sortArray(arr);\n        function swap(arr:number[],first:number,second:number):void{\n            [arr[first],arr[second]]=[arr[second],arr[first]];\n        }\n        function sortArray(arr:number[]){\n            let n=arr.length;\n            let low=0,mid=0,high=n-1;\n            while(mid\u003c=high){\n                if(arr[mid]==0){\n                    swap(arr,low++,mid++);\n                }else if(arr[mid]==2){\n                    swap(arr,mid,high--);\n                }else{\n                    mid++;\n                }\n            }\n            console.log(arr);\n        }\n        ```\n        \n        1. Move Negative left\n        \n        ```tsx\n        let arr=[-1,2,3,-3,4,-5];\n        sortArray(arr);\n        function sortArray(arr:number[]){\n            let n=arr.length;\n            let j=0;\n            for(let i=0;i\u003carr.length;i++){\n                if(arr[i]\u003c0){\n                    if(i!=j){\n                        let temp=arr[i];\n                        arr[i]=arr[j];\n                        arr[j]=temp;\n                    }\n                    j++;\n                }\n            }\n            console.log(arr);\n        }\n        ```\n        \n        1. Find Union and InterSection\n        \n        ```tsx\n        let arr1 = [1, 2, 3, 5, 6, 7, 8, 23];\n        let arr2 = [2, 3, 4, 5, 6];\n        const { union, intersection } = findUnionAndIntersection(arr1, arr2);\n        \n        console.log(\"Union:\", union);\n        console.log(\"Intersection:\", intersection);\n        \n        function findUnionAndIntersection(arr1: number[], arr2: number[]): { union: number[], intersection: number[] } {\n            const map = new Map\u003cnumber, number\u003e();\n            for (const item of arr1) {\n                map.set(item, (map.get(item) || 0) + 1);\n            }\n        \n            const unionSet = new Set(arr1);\n            const intersection: number[] = [];\n        \n            for (const item of arr2) {\n                if (map.has(item) \u0026\u0026 map.get(item)! \u003e 0) {\n                    map.set(item, map.get(item)! - 1);\n                    intersection.push(item);\n                }\n                unionSet.add(item);  // add item to the union set\n            }\n        \n            return {\n                union: Array.from(unionSet),  // convert the Set back to an array for the union\n                intersection\n            };\n        }\n        \n        ```\n        \n        1. Cyclic Rotate Array\n        \n        ```tsx\n        let arr=[1,2,3,4,4,6,8];\n        let k=2;\n        rotateLeft(arr,k);\n        rotateRight(arr,k);\n        function reverse(arr:number[],l:number,r:number):void{\n            while(l\u003cr){\n                let temp=arr[l];\n                arr[l]=arr[r];\n                arr[r]=temp;\n                l++;\n                r--;\n            }\n        }\n        function rotateLeft(arr:number[],k:number):void{\n        let n=arr.length;\n            reverse(arr,0,k-1);\n            reverse(arr,k,n-1);\n            reverse(arr,0,n-1);\n            console.log(\"reverse left= \",arr);\n        }\n        function rotateRight(arr:number[], k:number):void {\n          let n = arr.length;\n          reverse(arr, 0, n - k - 1);\n          reverse(arr, n - k, n - 1);\n          reverse(arr, 0, n - 1);\n          console.log(\"reverse right = \", arr);\n        }\n        \n        ```\n        \n        1. Sub Array Kadane\n        \n        ```tsx\n        const arr=[3,4,5,6,-1];\n        const n=arr.length;\n        const maxSum=maxSubArray(arr,n);\n        console.log(`The maximum subarray sum is: ${maxSum}`);\n        function maxSubArray(arr:number[],n:number):number{\n            let max=Number.MIN_SAFE_INTEGER;\n            let sum=0;\n            for(let i=0;i\u003cn;i++){\n                sum+=arr[i];\n                if(sum\u003emax){\n                    max=sum;\n                }if(sum\u003c0){\n                    sum=0;\n                }\n            }\n            return max;\n        }\n        ```\n        \n        1. Minimise Height\n        \n        ```tsx\n        const arr=[1,3,4,5,67,7];\n        const k=2;\n        console.log(getMinDiff(arr,arr.length,k));\n        function getMinDiff(arr:number[], n:number, k:number):number{\n        if(n==1){\n            return 0;\n        }\n        arr.sort((a,b)=\u003ea-b);\n        let ans=arr[n-1]-arr[0];\n        let small=arr[0]+k;\n        let big=arr[n-1]-k;\n        if(small\u003ebig){\n            [small,big]=[big,small];\n        }\n        for (let i = 1; i \u003c n - 1; i++) {\n            const height = arr[i];\n            const subtract = height - k;\n            const add = height + k;\n        \n            if (subtract \u003e= small || add \u003c= big) {\n              continue;\n            }\n        \n            if (big - subtract \u003c= add - small) {\n              small = subtract;\n            } else {\n              big = add;\n            }\n          }\n        \n          return Math.min(ans, big - small);\n        }\n        \n        ```\n        \n        1. Minimum Number of Jump\n        \n        ```tsx\n        let arr = [2, 3, 4, 5, 2, 3, 4, 8, 12];\n        let n = arr.length;\n        console.log(\"Minimum Jumps: \", minJumpBruteForce(arr, n));\n        \n        function minJumpBruteForce(arr: number[], n: number): number {\n            // If array has only one element, no jumps are needed\n            if (n === 1) return 0;\n            \n            // If the first element is 0, we can't make any jump\n            if (arr[0] === 0) return -1;\n            \n            let rng = arr[0];  // Maximum range reachable with current jump\n            let sl = arr[0];   // Steps left in the current jump\n            let jp = 1;        // Number of jumps taken\n        \n            for (let i = 1; i \u003c n; i++) {\n                // Check if we've reached the end\n                if (i === n - 1) return jp;\n                \n                // Update the maximum range reachable\n                rng = Math.max(rng, i + arr[i]);\n                sl--;  // Decrease steps left in the current jump range\n        \n                // If steps left become zero, we need another jump\n                if (sl === 0) {\n                    jp++;  // Increase jump count\n        \n                    // If the current maximum range is less than or equal to `i`, we can't move forward\n                    if (rng \u003c= i) return -1;\n        \n                    // Reset the steps left to reach `rng` from current position `i`\n                    sl = rng - i;\n                }\n            }\n        \n            // If we never reach the last index, return -1\n            return -1;\n        }\n        \n        ```\n        \n        1. Find Duplicates\n        \n        ```tsx\n        let arr = [1, 3, 4, 2, 3]; // Corrected array where 3 is the duplicate.\n        console.log(\"Duplicate no: \", findDuplicate(arr));\n        \n        function findDuplicate(arr: number[]): number {\n            let slow = arr[0];\n            let fast = arr[0];\n            \n            // Phase 1: Detect cycle using slow and fast pointers\n            do {\n                slow = arr[slow];         // move slow by 1 step\n                fast = arr[arr[fast]];    // move fast by 2 steps\n            } while (slow !== fast);      // continue until they meet\n        \n            // Phase 2: Find the entry point of the cycle (duplicate number)\n            fast = arr[0];  // Reset fast to the beginning of the array\n            while (slow !== fast) {\n                slow = arr[slow];   // move both slow and fast by 1 step\n                fast = arr[fast];\n            }\n            \n            return slow;  // Both pointers now point to the duplicate number\n        }\n        \n        ```\n        \n        1. Merge \n        \n        ```tsx\n        let arr1=[1,4,8,10];\n        let arr2=[2,3,4];\n        let n=4;\n        let m=3;\n        merge(arr1,arr2,n,m);\n        console.log(\"The merged arrays are: \");\n        console.log(\"arr1[] = \" + arr1.join(\" \"));\n        console.log(\"arr2[] = \" + arr2.join(\" \"));\n        function merge(arr1:number[],arr2:number[],n:number,m:number):void{\n            let left=n-1;\n            let right=0;\n            while(left\u003e0 \u0026\u0026 right\u003cm){\n                if(arr1[left]\u003earr2[right]){\n                    [arr1[left],arr2[right]]=[arr2[right],arr1[left]];\n                    left--;\n                    right++;\n                }else{\n                    break;\n                }\n            }\n            arr1.sort((a, b) =\u003e a - b);\n          arr2.sort((a, b) =\u003e a - b);\n        }\n        ```\n        \n        1. MergeIntervals\n        \n        ```tsx\n        \n        const arr = [\n          [1, 3],\n          [8, 10],\n          [2, 6],\n          [15, 18],\n        ];\n        const ans = mergeOverlappingInterval(arr);\n        console.log(\"The merged intervals are:\");\n        for (let it of ans) {\n          console.log(`[${it[0]}, ${it[1]}]`);\n        }\n        \n        function mergeOverlappingInterval(arr: number[][]): number[][] {\n          let n = arr.length;\n          arr.sort((a, b) =\u003e a[0] - b[0]);  // Sort intervals by the starting point\n        \n          const ans: number[][] = [arr[0]];  // Initialize the result with the first interval\n          for (let i = 1; i \u003c n; i++) {\n            const last = ans[ans.length - 1];  // Get the last interval in the result\n            const curr = arr[i];  // Get the current interval\n        \n            // Check if there is an overlap\n            if (curr[0] \u003c= last[1]) {\n              // Merge the intervals by updating the end of the last interval\n              last[1] = Math.max(curr[1], last[1]);\n            } else {\n              // No overlap, so add the current interval to the result\n              ans.push(curr);\n            }\n          }\n        \n          return ans;  // Return the merged intervals\n        }\n        \n        ```\n        \n        1. Next Permutation\n        \n        ```tsx\n        let a = [2, 4, 5, 6, 77, 6];\n        let ans = nextGreaterPermutation(a);\n        console.log(\"The next permutation is: [\" + ans.join(\" \") + \"]\");\n        \n        function nextGreaterPermutation(arr: number[]): number[] {\n            let n = arr.length;\n            let index = -1;\n        \n            // Step 1: Find the first index where arr[i] \u003c arr[i+1]\n            for (let i = n - 2; i \u003e= 0; i--) {\n                if (arr[i] \u003c arr[i + 1]) {\n                    index = i;\n                    break;\n                }\n            }\n        \n            // Step 2: If no such index is found, reverse the array\n            if (index === -1) {\n                arr.reverse();\n                return arr;\n            }\n        \n            // Step 3: Find the smallest number greater than arr[index] from the right side\n            for (let i = n - 1; i \u003e index; i--) {\n                if (arr[i] \u003e arr[index]) {\n                    [arr[i], arr[index]] = [arr[index], arr[i]]; // Swap them\n                    break;\n                }\n            }\n        \n            // Step 4: Reverse the subarray to the right of index\n            arr.splice(index + 1, n - index - 1, ...arr.slice(index + 1).reverse());\n        \n            return arr;\n        }\n        \n        ```\n        \n        1. Count Inversion\n        \n        ```tsx\n        const a: number[] = [5, 4, 3, 2, 1];\n        const cnt: number = numberOfInversionsOptimal(a);\n        console.log(\"The number of inversions is: \" + cnt);\n        \n        function numberOfInversionsNaive(arr: number[]): number {\n          let count = 0;\n          for (let i = 0; i \u003c arr.length; i++) {\n            for (let j = i + 1; j \u003c arr.length; j++) { // Changed 'i' to 'i+1' for proper comparison\n              if (arr[i] \u003e arr[j]) {\n                count++;\n              }\n            }\n          }\n          return count;\n        }\n        \n        function mergeSort(arr: number[], low: number, high: number): number {\n          let count = 0;\n          if (low \u003e= high) return count;\n          let mid = Math.floor((low + high) / 2);\n          count += mergeSort(arr, low, mid);\n          count += mergeSort(arr, mid + 1, high);\n          count += merge(arr, low, mid, high);\n          return count;\n        }\n        \n        function merge(arr: number[], low: number, mid: number, high: number): number {\n          const temp: number[] = [];\n          let left = low;\n          let right = mid + 1;\n          let count = 0;\n        \n          while (left \u003c= mid \u0026\u0026 right \u003c= high) {\n            if (arr[left] \u003c= arr[right]) {\n              temp.push(arr[left]);\n              left++;\n            } else {\n              temp.push(arr[right]);\n              count += mid - left + 1;\n              right++;\n            }\n          }\n        \n          while (left \u003c= mid) {\n            temp.push(arr[left]);\n            left++;\n          }\n        \n          while (right \u003c= high) {\n            temp.push(arr[right]);\n            right++;\n          }\n        \n          for (let i = low; i \u003c= high; i++) {\n            arr[i] = temp[i - low];\n          }\n        \n          return count;\n        }\n        \n        function numberOfInversionsOptimal(arr: number[]): number {\n          return mergeSort(arr, 0, arr.length - 1);\n        }\n        \n        ```\n        \n        1. Stock Buy And Sell\n        \n        ```tsx\n        let arr=[7,1,4,6,8,2];\n        let n=arr.length;\n        let maxProfit=getMaxProfit(arr,n);\n        console.log(\"Max Profit: \", maxProfit);\n        function getMaxProfit(arr:number[], n:number):number{\n            let ans=0;\n            let minPrice=Infinity;\n            for(let i=0;i\u003cn;i++){\n                minPrice=Math.min(minPrice,arr[i]);\n                ans=Math.max(ans,arr[i]-minPrice);\n            }\n            return ans;\n        }\n        ```\n        \n        17.  Compare Pair Sum\n        \n        ```tsx\n        let arr: number[] = [1, 5, 7, 1];\n        let k: number = 6;\n        let n: number = arr.length;\n        console.log(\"The number of pairs with sum:\", k, \":\", countPairs(arr, n, k));\n        \n        function countPairs(arr: number[], n: number, k: number): number {\n            let count = 0;\n            const freqMap = new Map\u003cnumber, number\u003e(); // Explicitly specifying the type of the map\n            for (let i = 0; i \u003c n; i++) {\n                const required = k - arr[i];\n                if (freqMap.has(required)) {\n                    count += freqMap.get(required)!; // Use non-null assertion since we know the value exists\n                }\n                freqMap.set(arr[i], (freqMap.get(arr[i]) || 0) + 1);\n            }\n            return count;\n        }\n        \n        ```\n        \n        1. Common Elements 3 sorted Array\n        \n        ```tsx\n        let A: number[] = [1, 5, 10, 20, 40, 80],\n            n1: number = A.length;\n        let B: number[] = [6, 7, 20, 80, 100],\n            n2: number = B.length;\n        let C: number[] = [3, 4, 15, 20, 30, 70, 80, 120],\n            n3: number = C.length;\n        \n        console.log(\"ans: \", commonElements(A, B, C, n1, n2, n3));\n        \n        // TC: O(n1 + n2 + n3) SC: O(1)\n        function commonElements(arr1: number[], arr2: number[], arr3: number[], n1: number, n2: number, n3: number): number[] {\n          let i = 0, j = 0, k = 0;\n          let res: number[] = [];\n          let last: number = Number.MIN_SAFE_INTEGER;\n          \n          while (i \u003c n1 \u0026\u0026 j \u003c n2 \u0026\u0026 k \u003c n3) {\n            if (arr1[i] === arr2[j] \u0026\u0026 arr1[i] === arr3[k] \u0026\u0026 arr1[i] !== last) {\n              res.push(arr1[i]);\n              last = arr1[i];\n              i++;\n              j++;\n              k++;\n            } else if (Math.min(arr1[i], arr2[j], arr3[k]) === arr1[i]) {\n              i++;\n            } else if (Math.min(arr1[i], arr2[j], arr3[k]) === arr2[j]) {\n              j++;\n            } else {\n              k++;\n            }\n          }\n          \n          if (res.length === 0) {\n            return [-1];\n          }\n          \n          return res;\n        }\n        \n        ```\n        \n        1. Rearrange by Sign\n        \n        ```tsx\n        let a: number[] = [1, -2, 3, -4, 5, -6];\n        let n: number = a.length;\n        let ans = rearrangeBySign(a, n);\n        console.log(ans.join(\" \"));\n        \n        function rearrangeBySign(a: number[], n: number): number[] {\n            let ans = new Array(n);\n            let posIndex = 0;\n            let negIndex = 1;\n        \n            // First, place negative numbers at odd indices and positive numbers at even indices\n            for (let i = 0; i \u003c n; i++) {\n                if (a[i] \u003c 0) {\n                    ans[negIndex] = a[i];\n                    negIndex += 2; // Move to next odd index\n                } else {\n                    ans[posIndex] = a[i];\n                    posIndex += 2; // Move to next even index\n                }\n            }\n        \n            // In case there are more positives or negatives and you still have unfilled spots, fill them in the remaining spots\n            if (posIndex \u003c n) {\n                for (let i = 0; i \u003c n; i++) {\n                    if (ans[i] === undefined) {\n                        ans[i] = a[i];\n                    }\n                }\n            }\n            \n            return ans;\n        }\n        \n        ```\n        \n        1. Sub Array k0\n        \n        ```tsx\n        let arr: number[] = [4, 2, -3, 1, 6];\n        let n: number = arr.length;\n        let k: number = 0;\n        \n        console.log(\"Subarray with sum k:\", findSubarrayOptimal(arr, n, k));\n        \n        // TC: O(n^2) - Naive solution\n        function findSubarrayNaive(arr: number[], n: number, k: number): boolean {\n          let isPresent = false;\n        \n          for (let i = 0; i \u003c n; i++) {\n            let sum = 0;\n            for (let j = i; j \u003c n; j++) {\n              sum += arr[j];\n              if (sum === k) {\n                isPresent = true;\n                break;\n              }\n            }\n            if (isPresent) break;\n          }\n          return isPresent;\n        }\n        \n        // TC: O(n) - Optimal solution using prefix sum and hash set\n        function findSubarrayOptimal(arr: number[], n: number, k: number): boolean {\n          let sum = 0;\n          let isPresent = false;\n          let prefixSum = new Set\u003cnumber\u003e();\n        \n          for (let i = 0; i \u003c n; i++) {\n            sum += arr[i];\n        \n            // Check if the current sum is equal to k, or if the difference (sum - k) exists in the prefixSum set\n            if (sum === k || prefixSum.has(sum - k)) {\n              isPresent = true;\n              break;\n            }\n        \n            // Add the current sum to the prefixSum set for future checks\n            prefixSum.add(sum);\n          }\n        \n          return isPresent;\n        }\n        \n        ```\n        \n        1. Max Product Sub Array\n        \n        ```tsx\n        let arr: number[] = [6, -3, -10, 0, 2];\n        let n: number = arr.length;\n        console.log(\"Max Product: \", getMaxProduct(arr, n));\n        \n        function getMaxProduct(arr: number[], n: number): number {\n            let maxEnd = arr[0];\n            let minEnd = arr[0];\n            let maxProd = arr[0];\n        \n            for (let i = 1; i \u003c n; i++) {\n                if (arr[i] \u003c 0) {\n                    // Swap maxEnd and minEnd when encountering a negative number\n                    let temp = maxEnd;\n                    maxEnd = minEnd;\n                    minEnd = temp;\n                }\n        \n                // Calculate max and min products ending at the current position\n                maxEnd = Math.max(arr[i], maxEnd * arr[i]);\n                minEnd = Math.min(arr[i], minEnd * arr[i]);\n        \n                // Update maxProd with the maximum product found so far\n                maxProd = Math.max(maxProd, maxEnd);\n            }\n        \n            return maxProd;\n        }\n        \n        ```\n        \n        1. Longes Consecutive Sucessive\n        \n        ```tsx\n        let arr: number[] = [100, 200, 1, 3, 4];\n        let ans = longestSuccessive(arr);\n        console.log(\"The longest consecutive sequence is:\", ans);\n        \n        function longestSuccessive(arr: number[]): number {\n            let n = arr.length;\n            if (n === 0) return 0;\n        \n            let longest = 1;\n            let st = new Set(arr);\n        \n            for (let it of st) {\n                // Only start counting sequence if it's the beginning of a sequence\n                if (!st.has(it - 1)) {\n                    let cnt = 1;\n                    let x = it;\n                    while (st.has(x + 1)) {\n                        x += 1;\n                        cnt += 1;\n                    }\n                    longest = Math.max(longest, cnt);\n                }\n            }\n            return longest;\n        }\n        \n        ```\n        \n        1. Element Appear NK times\n        \n        ```tsx\n        let arr: number[] = [2, 2, 1, 1, 1, 2, 2];\n        let n: number = arr.length;\n        let k: number = 2;\n        \n        // Naive Approach: Check each element and count its frequency\n        function majorityElementNaive(arr: number[], n: number, k: number): number {\n          for (let i = 0; i \u003c n; i++) {\n            let cnt = 0;\n            for (let j = 0; j \u003c n; j++) {\n              if (arr[i] == arr[j]) {\n                cnt++;\n              }\n            }\n            if (cnt \u003e Math.floor(n / k)) {\n              return arr[i];\n            }\n          }\n          return -1;\n        }\n        \n        // Better Approach: Use a hashmap to store frequencies\n        function majorityElementBetter(arr: number[], n: number, k: number): number[] {\n          let result: number[] = [];\n          const freqMap = new Map\u003cnumber, number\u003e();\n          const threshold = Math.floor(n / k) + 1;\n        \n          for (let i = 0; i \u003c n; i++) {\n            freqMap.set(arr[i], (freqMap.get(arr[i]) || 0) + 1);\n        \n            // If frequency meets threshold, add to result and remove from map to prevent duplicates\n            if (freqMap.get(arr[i]) === threshold) {\n              result.push(arr[i]);\n              freqMap.delete(arr[i]);\n            }\n          }\n          return result;\n        }\n        \n        // Majority Element for n/2 using Boyer-Moore Voting Algorithm\n        function majorityElementHalf(arr: number[]): number {\n          let count = 0;\n          let candidate: number | undefined;\n        \n          for (let num of arr) {\n            if (count === 0) {\n              candidate = num;\n            }\n            count += (num === candidate) ? 1 : -1;\n          }\n        \n          // Verify candidate frequency\n          let verifyCount = arr.filter(num =\u003e num === candidate).length;\n          return verifyCount \u003e Math.floor(arr.length / 2) ? candidate! : -1;\n        }\n        \n        // Majority Elements for n/3 using Extended Boyer-Moore Voting Algorithm\n        function majorityElementThird(arr: number[]): number[] {\n          let n = arr.length;\n          let count1 = 0, count2 = 0;\n          let candidate1: number | undefined, candidate2: number | undefined;\n        \n          for (let num of arr) {\n            if (candidate1 === num) {\n              count1++;\n            } else if (candidate2 === num) {\n              count2++;\n            } else if (count1 === 0) {\n              candidate1 = num;\n              count1 = 1;\n            } else if (count2 === 0) {\n              candidate2 = num;\n              count2 = 1;\n            } else {\n              count1--;\n              count2--;\n            }\n          }\n        \n          // Verify candidates\n          count1 = arr.filter(num =\u003e num === candidate1).length;\n          count2 = arr.filter(num =\u003e num === candidate2).length;\n          let result: number[] = [];\n          let threshold = Math.floor(n / 3) + 1;\n        \n          if (count1 \u003e= threshold) result.push(candidate1!);\n          if (count2 \u003e= threshold) result.push(candidate2!);\n        \n          return result;\n        }\n        \n        // Testing the functions\n        console.log(\"Naive Approach Majority Element:\", majorityElementNaive(arr, n, k));\n        console.log(\"Better Approach Majority Element:\", majorityElementBetter(arr, n, k));\n        console.log(\"Boyer-Moore Voting (n/2 Majority):\", majorityElementHalf(arr));\n        console.log(\"Extended Boyer-Moore Voting (n/3 Majority):\", majorityElementThird(arr));\n        \n        ```\n        \n        1. Max Profit 2 Data\n        \n        ```tsx\n        let price: number[] = [2, 30, 15, 10, 8, 25, 80];\n        let n: number = price.length;\n        console.log(\"Maximum Profit = \", maxProfitOptimal(price, n));\n        \n        // Function to calculate maximum profit with two transactions (O(2n) approach)\n        function maxProfit(arr: number[], n: number): number {\n          let profit: number[] = Array(n).fill(0);\n          let maxPrice = arr[n - 1];\n        \n          // Traverse from the right to find maximum selling profit\n          for (let i = n - 2; i \u003e= 0; i--) {\n            if (arr[i] \u003e maxPrice) {\n              maxPrice = arr[i];\n            }\n            profit[i] = Math.max(profit[i + 1], maxPrice - arr[i]);\n          }\n        \n          let minPrice = arr[0];\n        \n          // Traverse from the left to find maximum buying profit\n          for (let i = 1; i \u003c n; i++) {\n            if (arr[i] \u003c minPrice) {\n              minPrice = arr[i];\n            }\n            profit[i] = Math.max(profit[i - 1], profit[i] + (arr[i] - minPrice));\n          }\n        \n          return profit[n - 1];\n        }\n        \n        // Optimized function to calculate maximum profit with two transactions (O(n) approach)\n        function maxProfitOptimal(arr: number[], n: number): number {\n          let first_buy = -Infinity;\n          let first_sell = 0;\n          let second_buy = -Infinity;\n          let second_sell = 0;\n        \n          for (let i = 0; i \u003c n; i++) {\n            first_buy = Math.max(first_buy, -arr[i]); // max profit after buying the first stock\n            first_sell = Math.max(first_sell, first_buy + arr[i]); // max profit after selling the first stock\n            second_buy = Math.max(second_buy, first_sell - arr[i]); // max profit after buying the second stock\n            second_sell = Math.max(second_sell, second_buy + arr[i]); // max profit after selling the second stock\n          }\n        \n          return second_sell; // maximum profit with at most two transactions\n        }\n        \n        ```\n        \n        1. Subset of Other Array\n        \n        ```tsx\n        let a1: number[] = [11, 7, 1, 13, 21, 3, 7, 3];\n        let n: number = a1.length;\n        let a2: number[] = [11, 3, 7, 1, 7];\n        let m: number = a2.length;\n        console.log(isSubsetOptimal(a1, a2, n, m));\n        \n        // Naive approach to check if `a2` is a subset of `a1` (TC: O(n^2))\n        function isSubsetNaive(a1: number[], a2: number[], n: number, m: number): string {\n          let count = 0;\n        \n          for (let i = 0; i \u003c m; i++) {\n            let found = false;\n            for (let j = 0; j \u003c n; j++) {\n              if (a1[j] === a2[i]) {\n                count++;\n                a1[j] = -1; // Mark as used\n                found = true;\n                break;\n              }\n            }\n            if (!found) {\n              return \"No\"; // Element from a2 not found in a1\n            }\n          }\n        \n          return m === count ? \"Yes\" : \"No\";\n        }\n        \n        // Optimal approach using a hashmap to check if `a2` is a subset of `a1` (TC: O(n + m))\n        function isSubsetOptimal(a1: number[], a2: number[], n: number, m: number): string {\n          let freq = new Map\u003cnumber, number\u003e();\n        \n          // Count frequencies of elements in a1\n          for (let i = 0; i \u003c n; i++) {\n            freq.set(a1[i], (freq.get(a1[i]) || 0) + 1);\n          }\n        \n          // Check elements of a2 in the frequency map\n          for (let num of a2) {\n            if (!freq.has(num)) {\n              return \"No\";\n            }\n            freq.set(num, freq.get(num)! - 1);\n            if (freq.get(num)! \u003c 0) {\n              return \"No\";\n            }\n          }\n        \n          return \"Yes\";\n        }\n        \n        ```\n        \n        1. Three Sum\n        \n        ```tsx\n        let arr: number[] = [-1, 0, 1, 2, -1, -4];\n        let n: number = arr.length;\n        let k: number = 0;\n        let res = tripletOptimal(n, arr, k);\n        console.log(\"triplets: \", res);\n        \n        // Optimal approach (TC: O(n log n) + O(n^2), SC: O(no. of triplets))\n        function tripletOptimal(n: number, arr: number[], val: number): number[][] {\n          let ans: number[][] = [];\n          arr.sort((a, b) =\u003e a - b);\n        \n          for (let i = 0; i \u003c n; i++) {\n            if (i !== 0 \u0026\u0026 arr[i] === arr[i - 1]) continue;\n        \n            let j = i + 1;\n            let k = n - 1;\n            while (j \u003c k) {\n              let sum = arr[i] + arr[j] + arr[k];\n              if (sum \u003c val) {\n                j++;\n              } else if (sum \u003e val) {\n                k--;\n              } else {\n                ans.push([arr[i], arr[j], arr[k]]);\n                j++;\n                k--;\n        \n                // Skip duplicates for the second and third elements\n                while (j \u003c k \u0026\u0026 arr[j] === arr[j - 1]) j++;\n                while (j \u003c k \u0026\u0026 arr[k] === arr[k + 1]) k--;\n              }\n            }\n          }\n        \n          return ans;\n        }\n        \n        ```\n        \n        1. Trapping RainWater\n        \n        ```tsx\n        function trappingRainwater(height: number[]): number {\n          if (height.length === 0) return 0;\n        \n          let left = 0;\n          let right = height.length - 1;\n          let leftMax = 0;\n          let rightMax = 0;\n          let waterTrapped = 0;\n        \n          while (left \u003c= right) {\n            if (height[left] \u003c= height[right]) {\n              if (height[left] \u003e= leftMax) {\n                leftMax = height[left];\n              } else {\n                waterTrapped += leftMax - height[left];\n              }\n              left++;\n            } else {\n              if (height[right] \u003e= rightMax) {\n                rightMax = height[right];\n              } else {\n                waterTrapped += rightMax - height[right];\n              }\n              right--;\n            }\n          }\n        \n          return waterTrapped;\n        }\n        \n        // Example usage:\n        const height = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1];\n        console.log(\"Trapped Rainwater:\", trappingRainwater(height));\n        \n        ```\n        \n        1. Factorial of large number\n        \n        ```tsx\n        function largeNumberFactorial(n: number): number[] {\n          let result: number[] = [1]; // Initialize result to handle large numbers\n        \n          for (let i = 2; i \u003c= n; i++) {\n            multiply(i, result);\n          }\n        \n          return result.reverse(); // Reverse the array for readability\n        }\n        \n        function multiply(x: number, result: number[]): void {\n          let carry = 0;\n          \n          for (let i = 0; i \u003c result.length; i++) {\n            let product = result[i] * x + carry;\n            result[i] = product % 10;\n            carry = Math.floor(product / 10);\n          }\n        \n          while (carry \u003e 0) {\n            result.push(carry % 10);\n            carry = Math.floor(carry / 10);\n          }\n        }\n        \n        // Example usage:\n        const n = 100;\n        console.log(`Factorial of ${n}:`, largeNumberFactorial(n).join(\"\"));\n        \n        ```\n        \n    - Binary Search\n        1. Find X in Array\n        \n        ```tsx\n        let arr: number[] = [3, 4, 6, 7, 9, 12, 16];\n        let target: number = 6;\n        let index = search(arr, target);\n        if (index == -1) {\n            console.log(\"The target is not present\");\n        } else {\n            console.log(\"The target is at index:\", index);\n        }\n        \n        function search(arr: number[], target: number): number {\n            return binarySearch(arr, target);\n        }\n        \n        function binarySearch(arr: number[], target: number): number {\n            let low = 0;\n            let high = arr.length - 1; // Set high to the last valid index\n        \n            while (low \u003c= high) { // Adjust condition to \u003c=\n                let mid = Math.floor((low + high) / 2);\n                if (arr[mid] === target) {\n                    return mid;\n                } else if (arr[mid] \u003c target) {\n                    low = mid + 1;\n                } else {\n                    high = mid - 1;\n                }\n            }\n            return -1;\n        }\n        \n        ```\n        \n        1. Lower Bound\n        \n        ```tsx\n        let arr: number[] = [3, 5, 9, 12];\n        let x: number = 9;\n        let index = lowerBound(arr, arr.length, x);\n        console.log(\"The lower bound is at index:\", index);\n        \n        function lowerBound(arr: number[], n: number, x: number): number {\n            let low = 0, high = n - 1;\n            let ans = n; // Initialize ans with n, indicating \"not found\" if all elements are less than x\n        \n            while (low \u003c= high) {\n                let mid = Math.floor((low + high) / 2);\n                if (arr[mid] \u003e= x) {\n                    ans = mid; // Update ans with the current mid index\n                    high = mid - 1; // Move left to find the lowest index\n                } else {\n                    low = mid + 1; // Move right if arr[mid] \u003c x\n                }\n            }\n            return ans;\n        }\n        \n        ```\n        \n        1. Upper Bound\n        \n        ```tsx\n        let arr: number[] = [3, 5, 8, 9, 15, 19];\n        let x: number = 9;\n        let ind = upperBoundOptimal(arr, arr.length, x);\n        console.log(\"The upper bound is at index:\", ind);\n        \n        // TC: O(log n)\n        function upperBoundOptimal(arr: number[], n: number, x: number): number {\n          let low = 0;\n          let high = n - 1;\n          let ans = n; // Initialize ans with n, indicating \"not found\" if all elements are less than or equal to x\n        \n          while (low \u003c= high) {\n            let mid = Math.floor((low + high) / 2);\n            if (arr[mid] \u003e x) {\n              ans = mid; // Update ans with the current mid index\n              high = mid - 1; // Move left to find the lowest index with arr[mid] \u003e x\n            } else {\n              low = mid + 1; // Move right if arr[mid] \u003c= x\n            }\n          }\n          return ans;\n        }\n        \n        ```\n        \n        1. Search Insert Position\n        \n        ```tsx\n        let arr:number[]=[1,3,4,7];\n        let x=6;\n        let index=searchInsert(arr,x);\n        console.log(\"The index is: \",index);\n        function searchInsert(arr:number[], x:number):number{\n            let n=arr.length;\n            let low=0;\n            let high=n-1;\n            let ans=n;\n            while(low\u003c=high){\n                let mid=Math.floor((low+high)/2);\n                if(arr[mid]\u003e=x){\n                    ans=mid;\n                    high=mid-1;\n                }else{\n                    low=mid+1;\n                }\n                \n            }\n            return ans;\n        }\n        ```\n        \n        1. Floor Ceil\n        \n        ```tsx\n        let arr: number[] = [3, 4, 4, 7, 8, 10];\n        let n: number = arr.length;\n        let x: number = 8;\n        let ans = getFloorAndCeil(arr, n, x);\n        console.log(\"The floor and ceil are:\", ans[0], ans[1]);\n        \n        function getFloorAndCeil(arr: number[], n: number, x: number): [number, number] {\n          let floor = findFloor(arr, n, x);\n          let ceil = findCeil(arr, n, x);\n          return [floor, ceil];\n        }\n        \n        function findFloor(arr: number[], n: number, x: number): number {\n          let low = 0;\n          let high = n - 1;\n          let ans = -1;\n        \n          while (low \u003c= high) {\n            let mid = Math.floor((low + high) / 2);\n            if (arr[mid] \u003c= x) {\n              ans = arr[mid];\n              low = mid + 1;\n            } else {\n              high = mid - 1;\n            }\n          }\n          return ans;\n        }\n        \n        function findCeil(arr: number[], n: number, x: number): number {\n          let low = 0;\n          let high = n - 1;\n          let ans = -1;\n        \n          while (low \u003c= high) {\n            let mid = Math.floor((low + high) / 2);\n            if (arr[mid] \u003e= x) {\n              ans = arr[mid];\n              high = mid - 1;\n            } else {\n              low = mid + 1;\n            }\n          }\n          return ans;\n        }\n        \n        ```\n        \n        1. First Last Occurance\n        \n        ```tsx\n        let arr:number[]=[3,4,5,6,12,12,32];\n        let n:number=arr.length;\n        let k:number=12;\n        let ans=getLastOccurance(arr,n,k);\n        console.log(\"answer: \",ans);\n        function getLastOccurance(arr:number[],n:number,k:number):number{\n            let low=0,high=n-1,result=-1;\n            while(low\u003c=high){\n                let mid=Math.floor(low+(high-low)/2);\n                if(arr[mid]==k){\n                    result=mid;\n                    high=mid-1;\n                }\n                else if(k\u003carr[mid]){\n                    high=mid-1;\n                }else{\n                    low=mid+1;\n                }\n            }\n            return result;\n        }\n        ```\n        \n        1. Count Occurance\n        \n        ```tsx\n        \n        ```\n        \n        1. \n        \n        1. Search In Rotate\n    - Polly Fills\n        1. Filter\n        \n        ```tsx\n        interface Array\u003cT\u003e {\n          myOwnFilter(callback: (element: T, index: number) =\u003e boolean): T[];\n        }\n        \n        Array.prototype.myOwnFilter = function \u003cT\u003e(callback: (element: T, index: number) =\u003e boolean): T[] {\n          let newArr: T[] = [];\n          this.forEach((element: T, index: number) =\u003e {\n            if (callback(element, index)) {\n              newArr.push(element);\n            }\n          });\n          return newArr;\n        };\n        \n        let arr: number[] = [1, 3, 2, 4, 9, 5, 8, 6];\n        \n        const arrFiltered = arr.myOwnFilter((element, index) =\u003e {\n          return element \u003e 4;\n        });\n        \n        console.log(arrFiltered);\n        \n        ```\n        \n        1. For Each\n        \n        ```tsx\n        interface Array\u003cT\u003e {\n          myForEach(callback: (element: T, index: number) =\u003e void): void;\n        }\n        \n        Array.prototype.myForEach = function \u003cT\u003e(callback: (element: T, index: number) =\u003e void): void {\n          for (let i = 0; i \u003c this.length; i++) {\n            callback(this[i], i);\n          }\n        };\n        \n        const arr: number[] = [1, 2, 3, 4, 5];\n        \n        arr.myForEach((element, index) =\u003e {\n          console.log(`Element at index ${index}: ${element}`);\n        });\n        \n        ```\n        \n        1. Map\n        \n        ```tsx\n        // Adding myOwnMap method to Array prototype\n        interface Array\u003cT\u003e {\n          myOwnMap\u003cU\u003e(callback: (element: T, index: number) =\u003e U): U[];\n          myOwnReduce(callback: (accumulator: T, currentValue: T, index?: number, array?: T[]) =\u003e T, initialValue?: T): T;\n        }\n        \n        Array.prototype.myOwnMap = function \u003cT, U\u003e(callback: (element: T, index: number) =\u003e U): U[] {\n          const newArr: U[] = [];\n        \n          this.forEach((element: T, index: number) =\u003e {\n            const result = callback(element, index);\n            newArr.push(result);\n          });\n        \n          return newArr;\n        };\n        \n        const arr = [1, 3, 2, 4, 9, 5, 8, 6];\n        \n        const arr2 = arr.myOwnMap((element, index) =\u003e {\n          return element * 5;\n        });\n        \n        console.log(\"Mapped Array:\", arr2);\n        \n        ```\n        \n        1. Reduce\n        \n        ```tsx\n        // Extending the Array interface to include myOwnReduce\n        interface Array\u003cT\u003e {\n          myOwnReduce\u003cU\u003e(\n            callback: (accumulator: U, currentValue: T, index: number, array: T[]) =\u003e U,\n            initialValue?: U\n          ): U;\n        }\n        \n        // Adding myOwnReduce method to Array prototype\n        Array.prototype.myOwnReduce = function \u003cT, U\u003e(\n          this: T[],\n          callback: (accumulator: U, currentValue: T, index: number, array: T[]) =\u003e U,\n          initialValue?: U\n        ): U {\n          if (this.length === 0 \u0026\u0026 initialValue === undefined) {\n            throw new TypeError(\"Reduce of empty array with no initial value\");\n          }\n        \n          let accumulator: U = initialValue !== undefined ? initialValue : (this[0] as unknown as U);\n          const startIndex = initialValue !== undefined ? 0 : 1;\n        \n          for (let i = startIndex; i \u003c this.length; i++) {\n            accumulator = callback(accumulator, this[i], i, this);\n          }\n        \n          return accumulator;\n        };\n        \n        // Example usage\n        const arr = [1, 2, 3, 4];\n        const sum = arr.myOwnReduce\u003cnumber\u003e((accumulator, currentValue) =\u003e {\n          return accumulator + currentValue;\n        }, 0);\n        \n        console.log(\"Reduced Sum:\", sum); // Output: Reduced Sum: 10\n        \n        ```\n        \n    - Regex\n        \n        ```tsx\n        const string: string = \"all your string base belong to us\";\n        const regex: RegExp = /base/;\n        const isExisting: boolean = regex.test(string);\n        console.log(isExisting);\n        \n        ```\n        \n    - Sliding Window\n        1. Longest Sub String No Repeating Char\n        \n        ```jsx\n        let s: string = \"abcabcbb\";\n        console.log(lengthOfLongestSubString(s));\n        \n        function lengthOfLongestSubString(s: string): number {\n          let n = s.length;\n          let left = 0;\n          let right = 0;\n          let charSet = new Set\u003cstring\u003e(); // TypeScript: explicitly specifying the type of elements in the set\n          let maxLen = 0;\n        \n          while (right \u003c n) {\n            if (!charSet.has(s[right])) {\n              charSet.add(s[right]);\n              maxLen = Math.max(maxLen, right - left + 1);\n              right++;\n            } else {\n              charSet.delete(s[left]);\n              left++;\n            }\n          }\n        \n          return maxLen;\n        }\n        \n        ```\n        \n        1. Max Sub Array Size K\n        \n        ```jsx\n        function slidingWindowFixed(arr: number[], k: number): number | null {\n          const n = arr.length;\n          if (n \u003c k) return null;\n        \n          let left = 0;\n          let right = 0;\n          let maxSum = 0;\n          let currSum = 0;\n          const windowSet = new Set\u003cnumber\u003e();\n        \n          while (right \u003c n) {\n            if (!windowSet.has(arr[right]) \u0026\u0026 windowSet.size \u003c k) {\n              windowSet.add(arr[right]);\n              currSum += arr[right];\n              right++;\n            } else {\n              windowSet.delete(arr[left]);\n              currSum -= arr[left];\n              left++;\n            }\n        \n            if (windowSet.size === k) {\n              maxSum = Math.max(maxSum, currSum);\n              windowSet.delete(arr[left]);\n              currSum -= arr[left];\n              left++;\n            }\n          }\n          return maxSum;\n        }\n        function ifNotDistinct(arr: number[], k: number): number | null {\n          const n = arr.length;\n          if (n \u003c k) return null;\n        \n          let left = 0;\n          let right = 0;\n          let maxSum = 0;\n          let currentSum = 0;\n        \n          while (right \u003c n) {\n            currentSum += arr[right];\n        \n            if (right - left + 1 === k) {\n              maxSum = Math.max(maxSum, currentSum);\n              currentSum -= arr[left];\n              left++;\n            }\n        \n            right++;\n          }\n        \n          return maxSum;\n        }\n        let arr = [1, 5, 4, 2, 9, 9, 9];\n        let k = 3;\n        \n        console.log(slidingWindowFixed(arr, k)); // Output: Max sum of distinct elements within a sliding window\n        console.log(ifNotDistinct(arr, k));     // Output: Max sum of a fixed-size sliding window\n        \n        ```\n        \n        1. First Negative Number of Size K\n        \n        ```jsx\n        let arr: number[] = [-8, 2, 3, -6, 10];\n        let k: number = 2;\n        console.log(slidingWindowFixed(arr, k));\n        \n        function slidingWindowFixed(arr: number[], k: number): number[] {\n            const n = arr.length;\n            let left = 0;\n            let right = 0;\n            let window: number[] = [];\n            let result: number[] = [];\n        \n            while (right \u003c n) {\n                // Add negative numbers to the window\n                if (arr[right] \u003c 0) {\n                    window.push(arr[right]);\n                }\n        \n                console.log(window); // Debugging: logging window contents\n        \n                // When the window size reaches 'k', process the window\n                if (right - left + 1 === k) {\n                    // If there are no negative numbers in the window, push 0 to the result\n                    if (window.length === 0) {\n                        result.push(0);\n                    } else {\n                        // Otherwise, push the first negative number in the window (i.e., window[0])\n                        result.push(window[0]);\n        \n                        // If the element at the left of the window is the same as the first negative number,\n                        // remove it from the window\n                        if (arr[left] === window[0]) {\n                            window.shift();\n                        }\n                    }\n                    // Slide the window to the right\n                    left++;\n                }\n                right++;\n            }\n        \n            return result;\n        }\n        \n        ```\n        \n        1. Max Of All Sub Array\n        \n        ```jsx\n        function slidingWindowFixed(arr: number[], k: number): number[] {\n          const n = arr.length;\n          let left = 0;\n          let right = 0;\n          const ans: number[] = [];\n          let maxNum = Number.MIN_VALUE;\n        \n          while (right \u003c n) {\n            // Update the maximum number in the current window\n            if (arr[right] \u003e maxNum) {\n              maxNum = arr[right];\n            }\n        \n            // Check if the window size equals k\n            if (right - left + 1 === k) {\n              ans.push(maxNum); // Add the maximum value to the result array\n        \n              // If the leftmost element was the maximum, recalculate for the new window\n              if (arr[left] === maxNum) {\n                maxNum = Number.MIN_VALUE;\n                for (let i = left + 1; i \u003c= right; i++) {\n                  maxNum = Math.max(maxNum, arr[i]);\n                }\n              }\n        \n              left++; // Slide the window\n            }\n        \n            right++; // Expand the window\n          }\n        \n          return ans;\n        }\n        \n        // Example Usage\n        const arr: number[] = [1, 2, 3, 1, 4, 5, 2, 3, 6];\n        const k: number = 3;\n        console.log(slidingWindowFixed(arr, k)); // Output: [3, 3, 4, 5, 5, 5, 6]\n        \n        ```\n        \n        1. Max Consecutive longest Ones\n        \n        ```jsx\n        function longestOnes(arr: number[], k: number): number {\n          const n: number = arr.length;\n          let left: number = 0;\n          let right: number = 0;\n          let window: number = 0; // Count of `1`s in the current window\n          let ans: number = 0;\n        \n          while (right \u003c n) {\n            // Expand the window to include the current element\n            window += arr[right];\n        \n            // If the window condition is violated, shrink from the left\n            while (window + k \u003c right - left + 1) {\n              window -= arr[left];\n              left++;\n            }\n        \n            // Update the maximum size of the window\n            ans = Math.max(ans, right - left + 1);\n            right++;\n          }\n        \n          return ans;\n        }\n        \n        // Example Usage\n        const arr: number[] = [\n          0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1,\n        ];\n        const k: number = 3;\n        console.log(longestOnes(arr, k)); // Output: 10\n        \n        ```\n        \n        1. Max Fruit\n        \n        ```jsx\n        function findMaxFruits(arr: number[]): number {\n          const n: number = arr.length;\n          let left: number = 0;\n          let right: number = 0;\n          let ans: number = 0;\n        \n          const map: Map\u003cnumber, number\u003e = new Map();\n        \n          while (right \u003c n) {\n            // Add the current fruit to the map\n            map.set(arr[right], (map.get(arr[right]) || 0) + 1);\n        \n            // If there are more than 2 distinct types of fruits, shrink the window\n            while (map.size \u003e 2) {\n              const leftFruit = arr[left];\n              const count = map.get(leftFruit) || 0;\n        \n              if (count === 1) {\n                map.delete(leftFruit);\n              } else {\n                map.set(leftFruit, count - 1);\n              }\n              left++;\n            }\n        \n            // Update the maximum length\n            ans = Math.max(ans, right - left + 1);\n        \n            right++;\n          }\n        \n          return ans;\n        }\n        \n        // Example Usage\n        const arr: number[] = [1, 2, 1, 1, 3, 4, 2, 2, 2, 2, 4];\n        console.log(findMaxFruits(arr)); // Output: 5\n        \n        ```\n        \n        1. Character Replacement\n        \n        ```jsx\n        function characterReplacement(s: string, k: number): number {\n          const n: number = s.length;\n          const charCount: number[] = new Array(26).fill(0);\n          let maxCount: number = 0;\n          let maxLen: number = 0;\n          let left: number = 0;\n        \n          for (let right = 0; right \u003c n; right++) {\n            const charIndex: number = s.charCodeAt(right) - \"A\".charCodeAt(0);\n            charCount[charIndex]++;\n            maxCount = Math.max(maxCount, charCount[charIndex]);\n        \n            // Check if the current window is valid\n            while (right - left + 1 - maxCount \u003e k) {\n              const leftIndex: number = s.charCodeAt(left) - \"A\".charCodeAt(0);\n              charCount[leftIndex]--;\n              left++;\n            }\n        \n            // Update the maximum length\n            maxLen = Math.max(maxLen, right - left + 1);\n          }\n        \n          return maxLen;\n        }\n        \n        // Example Usage\n        const s: string = \"AABABBA\";\n        const k: number = 1;\n        console.log(characterReplacement(s, k)); // Output: 4\n        \n        ```\n        \n        1. Num SubArray with sum\n        \n        ```jsx\n        function numSubarraysWithSum(nums: number[], goal: number): number {\n          const prefixSumCount: Map\u003cnumber, number\u003e = new Map();\n          let sum: number = 0;\n          let count: number = 0;\n        \n          for (const num of nums) {\n            // Add current number to the cumulative sum\n            sum += num;\n        \n            // If the cumulative sum equals the goal, increment the count\n            if (sum === goal) {\n              count++;\n            }\n        \n            // Check if there exists a prefix sum that satisfies the condition\n            if (prefixSumCount.has(sum - goal)) {\n              count += prefixSumCount.get(sum - goal)!;\n            }\n        \n            // Update the prefixSumCount map\n            prefixSumCount.set(sum, (prefixSumCount.get(sum) || 0) + 1);\n          }\n        \n          return count;\n        }\n        \n        // Example Usage\n        const nums: number[] = [1, 0, 1, 0, 1];\n        const goal: number = 2;\n        console.log(numSubarraysWithSum(nums, goal)); // Output: 4\n        \n        ```\n        \n        1. Number of Sub Arrays\n        \n        ```jsx\n        function numberOfSubarrays(nums: number[], k: number): number {\n          const n: number = nums.length;\n          let left: number = 0;\n          let right: number = 0;\n          let niceSubArray: number = 0;\n          let result: number = 0;\n          let countOdd: number = 0;\n        \n          while (right \u003c n) {\n            // Count odd numbers in the current window\n            if (nums[right] % 2 !== 0) {\n              countOdd++;\n            }\n        \n            // When the current window has exactly k odd numbers\n            if (countOdd === k) {\n              niceSubArray = 0;\n            }\n        \n            // Shrink the window from the left while maintaining k odd numbers\n            while (countOdd \u003e= k) {\n              if (nums[left] % 2 !== 0) {\n                countOdd--;\n              }\n              left++;\n              niceSubArray++;\n            }\n        \n            // Add the count of valid subarrays for the current window\n            result += niceSubArray;\n            right++;\n          }\n        \n          return result;\n        }\n        \n        // Example Usage\n        const nums: number[] = [1, 1, 2, 1, 1];\n        const k: number = 3;\n        console.log(numberOfSubarrays(nums, k)); // Output: 2\n        \n        ```\n        \n        1. Number of substring\n        \n        ```jsx\n        function numberOfSubstrings(s: string): number {\n          const freq: Record\u003cstring, number\u003e = { a: 0, b: 0, c: 0 };\n          const n: number = s.length;\n          let left: number = 0;\n          let right: number = 0;\n          let count: number = 0;\n          let missing: number = 3; // Counts how many of 'a', 'b', 'c' are missing in the window\n        \n          while (right \u003c n) {\n            // Add the character at `right` to the frequency map\n            if (++freq[s[right]] === 1) {\n              missing--; // Decrease `missing` if a new character is added\n            }\n        \n            // When all characters are present in the window\n            while (missing === 0) {\n              // All substrings starting from the current `left` to the end are valid\n              count += n - right;\n        \n              // Remove the character at `left` from the window\n              if (--freq[s[left]] === 0) {\n                missing++; // Increase `missing` if a character is removed completely\n              }\n              left++; // Shrink the window\n            }\n        \n            right++; // Expand the window\n          }\n        \n          return count;\n        }\n        \n        // Example Usage\n        const s: string = \"abcabc\";\n        console.log(numberOfSubstrings(s)); // Output: 10\n        \n        ```\n        \n    - Sorting\n        \n        Selection Sort\n        \n        ```tsx\n        let arr: number[] = [13, 46, 24, 52, 20, 9];\n        let n: number = arr.length;\n        console.log(\"Selection Sort: \", selectionSort(arr, n));\n        \n        // TC: O(n^2) SC: O(1)\n        function selectionSort(arr: number[], n: number): number[] {\n          for (let i = 0; i \u003c n - 1; i++) {\n            let min: number = i;\n            for (let j = i + 1; j \u003c n; j++) {\n              if (arr[j] \u003c arr[min]) {\n                min = j;\n              }\n            }\n            let temp: number = arr[i];\n            arr[i] = arr[min];\n            arr[min] = temp;\n          }\n          return arr;\n        }\n        \n        ```\n        \n        Quick Sort\n        \n        ```tsx\n        const arr: number[] = [4, 6, 2, 5, 7, 9, 1, 3];\n        console.log(\"Before Using Quicksort: \", arr);\n        sortArray(arr);\n        console.log(\"After Quicksort: \", arr);\n        \n        function partition(arr: number[], low: number, high: number): number {\n          const pivot: number = arr[low];\n          let i: number = low;\n          let j: number = high;\n        \n          while (i \u003c j) {\n            while (arr[i] \u003c= pivot \u0026\u0026 i \u003c= high - 1) {\n              i++;\n            }\n        \n            while (arr[j] \u003e pivot \u0026\u0026 j \u003e= low + 1) {\n              j--;\n            }\n        \n            if (i \u003c j) {\n              const temp: number = arr[i];\n              arr[i] = arr[j];\n              arr[j] = temp;\n            }\n          }\n        \n          const temp: number = arr[low];\n          arr[low] = arr[j];\n          arr[j] = temp;\n          return j;\n        }\n        \n        function quickSort(arr: number[], low: number, high: number): void {\n          if (low \u003c high) {\n            const pIndex: number = partition(arr, low, high);\n            quickSort(arr, low, pIndex - 1);  // Recursively sort the left part\n            quickSort(arr, pIndex + 1, high); // Recursively sort the right part\n          }\n        }\n        \n        function sortArray(arr: number[]): number[] {\n          quickSort(arr, 0, arr.length - 1);\n          return arr;\n        }\n        \n        ```\n        \n        Merge Sort\n        \n        ```tsx\n        let arr: number[] = [13, 46, 24, 52, 20, 9];\n        let n: number = arr.length;\n        mergeSort(arr, 0, n - 1);\n        console.log(\"Merge sort: \", arr);\n        \n        // Time complexity: O(n log n)  // Space complexity: O(n)\n        function mergeSort(arr: number[], low: number, high: number): void {\n          if (low \u003e= high) return;\n          \n          let mid: number = Math.floor((low + high) / 2);\n          mergeSort(arr, low, mid);         // Sort the left half\n          mergeSort(arr, mid + 1, high);    // Sort the right half\n          merge(arr, low, mid, high);       // Merge both halves\n        }\n        \n        function merge(arr: number[], low: number, mid: number, high: number): void {\n          const temp: number[] = [];\n          let left: number = low;\n          let right: number = mid + 1;\n        \n          while (left \u003c= mid \u0026\u0026 right \u003c= high) {\n            if (arr[left] \u003c= arr[right]) {\n              temp.push(arr[left]);\n              left++;\n            } else {\n              temp.push(arr[right]);\n              right++;\n            }\n          }\n        \n          // Add remaining elements from the left part\n          while (left \u003c= mid) {\n            temp.push(arr[left]);\n            left++;\n          }\n        \n          // Add remaining elements from the right part\n          while (right \u003c= high) {\n            temp.push(arr[right]);\n            right++;\n          }\n        \n          // Copy the sorted elements back into the original array\n          for (let i = low; i \u003c= high; i++) {\n            arr[i] = temp[i - low];\n          }\n        }\n        \n        ```\n        \n        Insertion Sort\n        \n        ```tsx\n        let arr:number[]=[23,23,43,34,5,6];\n        let n:number=arr.length;\n        insertionSort(arr,n);\n        console.log(\"Insertion sort: \", arr);\n        function insertionSort(arr:number[],n:number):number[]{\n            for(let i=0;i\u003cn;i++){\n                let j=i;\n                while(j\u003e0 \u0026\u0026 arr[j-1]\u003earr[j]){\n                    let temp=arr[j];\n                    arr[j]=arr[j-1];\n                    arr[j-1]=temp;\n                    j--;\n                }\n            }\n            return arr;\n        }\n        ```\n        \n        Buuble Sort\n        \n        ```tsx\n        let arr: number[] = [12, 3, 2, 45, 34];\n        let n: number = arr.length;\n        bubbleSort(arr, n);\n        console.log(\"Bubble Sort:\", arr);\n        \n        function bubbleSort(arr: number[], n: number): void {\n            for (let turn = 0; turn \u003c n - 1; turn++) {\n                for (let j = 0; j \u003c n - turn - 1; j++) {  // Fixed range for `j`\n                    if (arr[j] \u003c arr[j + 1]) {  // Sort in descending order\n                        let temp = arr[j];\n                        arr[j] = arr[j + 1];\n                        arr[j + 1] = temp;\n                    }\n                }\n            }\n        }\n        \n        ```\n        \n    - String\n        1. Remove Outer most String\n        \n        ```tsx\n        let s: string = \"(()())(())\";\n        let ans: string = removeOuterParentheses(s);\n        console.log(\"ans: \", ans);\n        \n        function removeOuterParentheses(s: string): string {\n          let res: string = \"\";\n          let bal: number = 0;\n          \n          for (let ch of s) {\n            if (ch === \"(\") {\n              if (bal \u003e 0) {\n                res += \"(\";\n              }\n              bal++;\n            } else if (ch === \")\") {\n              bal--;\n              if (bal \u003e 0) {\n                res += \")\";\n              }\n            }\n          }\n        \n          return res;\n        }\n        \n        ```\n        \n        1. Reverse String\n        \n        ```tsx\n        let str: string = \"hello\";\n        let ans = reverse(str);\n        console.log(\"ans: \", ans);\n        \n        function reverse(str: string): string {\n          let strArr = str.split(\"\");\n          let low = 0;\n          let high = strArr.length - 1; // Adjusted high index to length - 1\n        \n          while (low \u003c high) {\n            [strArr[low], strArr[high]] = [strArr[high], strArr[low]];\n            low++;\n            high--;\n          }\n        \n          return strArr.join(\"\");\n        }\n        \n        ```\n        \n        1. Reverse Word\n        \n        ```tsx\n        let str:string=\"this is and amazing program\";\n        console.log(reverseWords(str));\n        function reverseWords(str:string){\n            let reversedWord=\"\";\n            let reversedStr=\"\";\n             for (let i = 0; i \u003c str.length; i++) {\n            if (str[i] !== \" \") {\n              reversedWord = str[i] + reversedWord;\n            } else {\n              reversedStr += reversedWord + \" \";\n              reversedWord = \"\";\n            }\n          }\n          // Handle the last word\n          reversedStr += reversedWord;\n          return reversedStr;\n        }\n        ```\n        \n        1. Duplicate Char String\n        \n        ```tsx\n        let str: string = \"test string\";\n        printDuplicate(str);\n        console.log(str);\n        \n        function printDuplicate(str: string) {\n            const charCount: { [key: string]: number } = {};  // Using an object to store character counts\n            for (let i = 0; i \u003c str.length; i++) {\n                const char = str[i];  // Getting the character at index i\n                if (charCount[char]) {\n                    charCount[char]++;\n                } else {\n                    charCount[char] = 1;\n                }\n            }\n        \n            console.log(\"Character counts:\", charCount);\n            return charCount;\n        }\n        \n        ```\n        \n        1. Odd Number In String\n        \n        ```tsx\n        let num: string = \"52\";\n        let largestOdd = largestOddNumber(num);\n        console.log(largestOdd);  // This will now print the correct output\n        \n        function largestOddNumber(num: string): string {\n            for (let i = num.length - 1; i \u003e= 0; i--) {\n                if (parseInt(num[i]) % 2 === 1) {\n                    return num.substring(0, i + 1);  // Extracts the substring from the start to the first odd digit\n                }\n            }\n            return \"\";  // If no odd digit found, return an empty string\n        }\n        \n        ```\n        \n        1. Longest Common Prefix\n        \n        ```tsx\n        let strs: string[] = [\"flower\", \"flow\", \"flight\"];\n        let ans: string = longestCommonPrefix(strs);\n        console.log(\"ans: \", ans);\n        \n        function longestCommonPrefix(strs: string[]): string {\n          if (strs.length === 0) {\n            return \"\";\n          }\n        \n          const reference: string = strs[0];\n        \n          for (let i = 0; i \u003c reference.length; i++) {\n            const char: string = reference[i];\n            for (let j = 1; j \u003c strs.length; j++) {\n              if (i \u003e= strs[j].length || strs[j][i] !== char) {\n                return reference.slice(0, i);\n              }\n            }\n          }\n          return reference;\n        }\n        \n        ```\n        \n        1. Palindrome\n        \n        ```tsx\n        let s: string = \"abba\";\n        console.log(isPalindrome(s));  // Output will be true or false\n        \n        function isPalindrome(s: string): boolean {\n            let left = 0, right = s.length - 1;\n            while (left \u003c right) {\n                if (s[left] !== s[right]) {\n                    return false;  // Return false if not a palindrome\n                }\n                left++;\n                right--;\n            }\n            return true;  // Return true if palindrome\n        }\n        ```\n        \n        1. Isomorphic String\n        \n        ```tsx\n        function isIsomorphic(s: string, t: string): boolean {\n          if (s.length !== t.length) return false;\n        \n          const mpp = new Map\u003cstring, string\u003e();\n        \n          for (let i = 0; i \u003c s.length; i++) {\n            const original = s[i];\n            const replacement = t[i];\n            if (!mpp.has(original)) {\n              // Ensure no character in `t` is already mapped to another character in `s`\n              if (![...mpp.values()].includes(replacement)) {\n                mpp.set(original, replacement);\n              } else {\n                return false;\n              }\n            } else {\n              const mappedChar = mpp.get(original);\n              if (mappedChar !== replacement) {\n                return false;\n              }\n            }\n          }\n          return true;\n        }\n        \n        let s: string = \"egg\";\n        let t: string = \"add\";\n        console.log(\"ans: \", isIsomorphic(s, t));  // Output will be true or false\n        \n        ```\n        \n        1. Check if Valid Anagram\n        \n        ```tsx\n        function isValidAnagramOptimal(s: string, t: string): boolean {\n          // If lengths are different, they cannot be anagrams\n          if (s.length !== t.length) {\n            return false;\n          }\n        \n          // Initialize a frequency array for characters (assuming uppercase English letters)\n          let freq = new Array(26).fill(0);\n        \n          // Count the frequency of characters in s\n          for (let i = 0; i \u003c s.length; i++) {\n            freq[s.charCodeAt(i) - \"A\".charCodeAt(0)]++;\n          }\n        \n          // Subtract the frequency of characters in t\n          for (let i = 0; i \u003c t.length; i++) {\n            freq[t.charCodeAt(i) - \"A\".charCodeAt(0)]--;\n          }\n        \n          // Check if all frequencies are zero, meaning the strings are anagrams\n          for (let i = 0; i \u003c 26; i++) {\n            if (freq[i] !== 0) {\n              return false;\n            }\n          }\n        \n          return true;\n        }\n        \n        // Example usage:\n        let s: string = \"INTEGER\";\n        let t: string = \"TEGERNI\";\n        console.log(isValidAnagramOptimal(s, t));  // Output: true\n        \n        ```\n        \n        1. Sort Char Freq\n        \n        ```tsx\n        function freqSort(s: string): string {\n          let map = new Map\u003cstring, number\u003e();  // Map to store character frequencies\n          let str = \"\";\n        \n          // Populate the map with the frequency of each character\n          for (let i = 0; i \u003c s.length; i++) {\n            if (!map.has(s[i])) {\n              map.set(s[i], 1);\n            } else {\n              map.set(s[i], map.get(s[i])! + 1); // Using non-null assertion for the value\n            }\n          }\n        \n          // Sort the map entries by frequency in descending order\n          const newMap = new Map([...map.entries()].sort((a, b) =\u003e b[1] - a[1]));\n        \n          // Build the final string based on the sorted frequencies\n          for (let [i, j] of newMap) {\n            str += i.repeat(j);\n          }\n        \n          return str;\n        }\n        \n        // Example usage:\n        let s: string = \"tree\";\n        console.log(\"ans: \", freqSort(s));  // Output: \"eetr\"\n        \n        ```\n        \n        1. Max Depth Parenthesis\n        \n        ```tsx\n        function maxDepth(s: string): number {\n          let maxDepth = 0;\n          let currDept = 0;\n        \n          for (let i = 0; i \u003c s.length; i++) {\n            let ch = s[i];\n            if (ch === \"(\") {\n              currDept++;\n              maxDepth = Math.max(maxDepth, currDept);\n            } else if (ch === \")\") {\n              currDept--;\n            }\n          }\n          return maxDepth;\n        }\n        \n        // Example usage:\n        let s: string = \"(1+(2*3)+((8)/4))+1\";\n        console.log(maxDepth(s));  // Output: 3\n        \n        ```\n        \n        1. Roman To Integer\n        \n        ```tsx\n        function romanToInt(s: string): number {\n          let map = new Map\u003cstring, number\u003e();\n          map.set(\"I\", 1);\n          map.set(\"V\", 5);\n          map.set(\"X\", 10);\n          map.set(\"L\", 50);\n          map.set(\"C\", 100);\n          map.set(\"D\", 500);\n          map.set(\"M\", 1000);\n        \n          let result = 0;\n          for (let i = 0; i \u003c s.length; i++) {\n            let curr = map.get(s[i])!;\n            let next = map.get(s[i + 1])!;\n            if (curr \u003c next) {\n              result -= curr; // Subtract the current value if it's less than the next\n            } else {\n              result += curr; // Add the current value otherwise\n            }\n          }\n          return result;\n        }\n        \n        // Example usage:\n        let s: string = \"LVIII\";\n        console.log(\"ans: \", romanToInt(s));  // Output: 58\n        \n        ```\n        \n        1. Integer to Roman\n        \n        ```tsx\n        function integerToRomanNaive(num: number): string {\n          const map = new Map\u003cnumber, string\u003e();\n          map.set(1, \"I\");\n          map.set(5, \"V\");\n          map.set(10, \"X\");\n          map.set(50, \"L\");\n          map.set(100, \"C\");\n          map.set(500, \"D\");\n          map.set(1000, \"M\");\n        \n          let base = 1;\n          const result: string[] = [];\n          while (num \u003e 0) {\n            const last = num % 10;\n            if (last \u003c 4) {\n              for (let k = last; k \u003e 0; k--) {\n                result.unshift(map.get(base)!);\n              }\n            } else if (last == 4) {\n              result.unshift(...[map.get(base)!, map.get(base * 5)!]);\n            } else if (last == 5) {\n              result.unshift(map.get(base * 5)!);\n            } else if (last \u003c 9) {\n              for (let k = last; k \u003e 5; k--) {\n                result.unshift(map.get(base)!);\n              }\n              result.unshift(map.get(base * 5)!);\n            } else {\n              result.unshift(...[map.get(base)!, map.get(base * 10)!]);\n            }\n            base *= 10;\n            num = (num - last) / 10;\n          }\n          return result.join(\"\");\n        }\n        \n        function integerToRomanOptimal(num: number): string {\n          const map: [string, number][] = [\n            [\"M\", 1000],\n            [\"CM\", 900],\n            [\"D\", 500],\n            [\"CD\", 400],\n            [\"C\", 100],\n            [\"XC\", 90],\n            [\"L\", 50],\n            [\"XL\", 40],\n            [\"X\", 10],\n            [\"IX\", 9],\n            [\"V\", 5],\n            [\"IV\", 4],\n            [\"I\", 1],\n          ];\n        \n          let res = \"\";\n        \n          for (const [roman, val] of map) {\n            while (num \u003e= val) {\n              res += roman;\n              num -= val;\n            }\n          }\n          return res;\n        }\n        \n        // Example usage:\n        let num: number = 58;\n        console.log(\"ans: \", integerToRomanOptimal(num)); // Output: \"LVIII\"\n        \n        ```\n        \n        1. Count Distinct Character\n        \n        ```tsx\n        let str: string = \"aabab\";\n        let k: number = 2;\n        console.log(\"ans: \", countSubstringsWithKDistinctCharsOptimal(str, k));\n        \n        function countSubstringsWithKDistinctCharsBruteForce(str: string, k: number): number {\n          let n: number = str.length;\n          let count: number = 0;\n        \n          for (let i = 0; i \u003c n; i++) {\n            for (let j = i; j \u003c n; j++) {\n              const substring: string = str.slice(i, j + 1);\n              const distinctChars = new Set(substring);\n              if (distinctChars.size === k) {\n                count++;\n              }\n            }\n          }\n          return count;\n        }\n        \n        function most_k_chars(s: string, k: number): number {\n          if (!s) {\n            return 0;\n          }\n        \n          const char_count: { [key: string]: number } = {};\n          let num: number = 0;\n          let left: number = 0;\n        \n          for (let i = 0; i \u003c s.length; i++) {\n            char_count[s[i]] = (char_count[s[i]] || 0) + 1;\n            while (Object.keys(char_count).length \u003e k) {\n              char_count[s[left]] -= 1;\n              if (char_count[s[left]] === 0) {\n                delete char_count[s[left]];\n              }\n              left += 1;\n            }\n            num += i - left + 1;\n          }\n          return num;\n        }\n        \n        function countSubstringsWithKDistinctCharsOptimal(str: string, k: number): number {\n          return most_k_chars(str, k) - most_k_chars(str, k - 1);\n        }\n        \n        ```\n        \n        1. Longest Palindrome\n        \n        ```tsx\n        let s: string = \"babad\";\n        console.log(longestPalindromeOptimal(s));\n        \n        // TC: O(n^3), SC: O(1)\n        function longestPalindrome(s: string): string {\n          let n: number = s.length;\n          let longest: string = \"\";\n          for (let i = 0; i \u003c n; i++) {\n            for (let j = i + 1; j \u003c= n; j++) {\n              const substring: string = s.slice(i, j);\n              if (isPalindrome(substring) \u0026\u0026 substring.length \u003e longest.length) {\n                longest = substring;\n              }\n            }\n          }\n          return longest;\n        }\n        \n        function isPalindrome(str: string): boolean {\n          const n: number = str.length;\n          for (let i = 0; i \u003c Math.floor(n / 2); i++) {\n            if (str[i] !== str[n - 1 - i]) {\n              return false;\n            }\n          }\n          return true;\n        }\n        \n        function expandOverCenter(str: string, left: number, right: number): string {\n          let n: number = str.length;\n          while (left \u003e= 0 \u0026\u0026 right \u003c n \u0026\u0026 str[left] === str[right]) {\n            left--;\n            right++;\n          }\n          return str.slice(left + 1, right);\n        }\n        \n        function longestPalindromeOptimal(s: string): string {\n          const n: number = s.length;\n          let maxPalindrome: string = \"\";\n          for (let i = 0; i \u003c n; i++) {\n            const palindrom1: string = expandOverCenter(s, i, i);\n            const palindrom2: string = expandOverCenter(s, i, i + 1);\n        \n            if (palindrom1.length \u003e maxPalindrome.length) {\n              maxPalindrome = palindrom1;\n            }\n            if (palindrom2.length \u003e maxPalindrome.length) {\n              maxPalindrome = palindrom2;\n            }\n          }\n          return maxPalindrome;\n        }\n        \n        ```\n        \n        1. Sum of beauty\n        \n        ```tsx\n        let s: string = \"aabcb\";\n        console.log(sumOfBeautiesOptimal(s));\n        \n        function sumOfBeautiesNaive(s: string): number {\n          let n: number = s.length;\n          let beautySum: number = 0;\n        \n          for (let i = 0; i \u003c n; i++) {\n            for (let j = i + 1; j \u003c n; j++) {\n              const substring: string = s.slice(i, j);\n              beautySum += calculateBeauty(substring);\n            }\n          }\n          return beautySum;\n        }\n        \n        function calculateBeauty(substring: string): number {\n          const charCount: Map\u003cstring, number\u003e = new Map();\n          let maxCount: number = 0;\n          let minCount: number = Number.MAX_VALUE;\n        \n          for (let i = 0; i \u003c substring.length; i++) {\n            const char: string = substring[i];\n            charCount.set(char, (charCount.get(char) || 0) + 1);\n            maxCount = Math.max(maxCount, charCount.get(char)!);\n            minCount = Math.min(minCount, charCount.get(char)!);\n          }\n          return maxCount - minCount;\n        }\n        \n        function sumOfBeautiesOptimal(s: string): number {\n          let beautySum: number = 0;\n          const limit: number = s.length;\n        \n          for (let i = 0; i \u003c limit; i++) {\n            const freq: number[] = new Array(26).fill(0);\n            for (let j = i; j \u003c limit; j++) {\n              freq[s.charCodeAt(j) - \"a\".charCodeAt(0)]++;\n              beautySum += calculateBeautyFreq(freq);\n            }\n          }\n          return beautySum;\n        }\n        \n        function calculateBeautyFreq(freq: number[]): number {\n          let max: number = -Infinity;\n          let min: number = Infinity;\n        \n          for (let i = 0; i \u003c 26; i++) {\n            if (freq[i] !== 0) {\n              max = Math.max(max, freq[i]);\n              min = Math.min(min, freq[i]);\n            }\n          }\n          return max - min;\n        }\n        \n        ```\n        \n        1. Atoi\n        \n        ```tsx\n        function atoi(str: string): number {\n          // Remove leading whitespace\n          str = str.trim();\n        \n          // Check for empty string\n          if (!str) return 0;\n        \n          // Initialize variables\n          let sign: number = 1;\n          let result: number = 0;\n          let index: number = 0;\n        \n          // Determine sign\n          if (str[index] === '-') {\n            sign = -1;\n            index++;\n          } else if (str[index] === '+') {\n            index++;\n          }\n        \n          // Convert characters to integer until a non-digit is encountered\n          while (index \u003c str.length \u0026\u0026 str[index] \u003e= '0' \u0026\u0026 str[index] \u003c= '9') {\n            const digit: number = str.charCodeAt(index) - '0'.charCodeAt(0);\n            result = result * 10 + digit;\n            index++;\n            \n            // Handle overflow for 32-bit signed integer range\n            if (result * sign \u003c -2147483648) return -2147483648;\n            if (result * sign \u003e 2147483647) return 2147483647;\n          }\n        \n          return result * sign;\n        }\n        console.log(atoi(\"42\"));           \n        ```\n        \n    - Stack\n        1. Stack Using Array\n        \n        ```tsx\n        const myStack: string[] = [];\n        myStack.push(\"a\");\n        myStack.push(\"b\");\n        myStack.push(\"c\");\n        console.log(myStack); // Output: ['a', 'b', 'c']\n        \n        myStack.pop();\n        myStack.push(\"e\");\n        myStack.push(\"f\");\n        console.log(myStack); // Output: ['a', 'b', 'e', 'f']\n        ```\n        \n        1. Stack Using LinkedList\n        \n        ```tsx\n        class StackNode {\n          value: string;\n          next: StackNode | null;\n        \n          constructor(value: string) {\n            this.value = value;\n            this.next = null;\n          }\n        }\n        \n        class Stack {\n          top: StackNode | null;\n          size: number;\n        \n          constructor() {\n            this.top = null;\n            this.size = 0;\n          }\n        \n          push(val: string): void {\n            const newNode = new StackNode(val);\n            if (this.size === 0) {\n              this.top = newNode;\n            } else {\n              newNode.next = this.top;\n              this.top = newNode;\n            }\n            this.size++;\n          }\n        \n          getTop(): string | null {\n            if (this.size === 0) return null;\n            return this.top?.value || null;\n          }\n        \n          pop(): string | null {\n            if (this.size === 0) return null;\n            const node = this.top;\n            if (node) {\n              this.top = node.next;\n              this.size--;\n              return node.value;\n            }\n            return null;\n          }\n        }\n        \n        // Testing the Stack\n        const stack = new Stack();\n        stack.push(\"a\");\n        stack.push(\"b\");\n        stack.push(\"c\");\n        stack.push(\"d\");\n        \n        console.log(stack.pop()); // Output: \"d\"\n        console.log(stack.pop()); // Output: \"c\"\n        console.log(stack.pop()); // Output: \"b\"\n        console.log(stack.pop()); // Output: \"a\"\n        console.log(stack.getTop()); // Output: null\n        ```\n        \n        1. Queue Using ArrayList\n        \n        ```tsx\n        const queue:string[]=[];\n        queue.push(\"a\");\n        queue.push(\"b\");\n        queue.push(\"c\");\n        queue.push(\"d\");\n        console.log(queue);\n        queue.shift();\n        console.log(queue);\n        ```\n        \n        1. Queue using LinkedList\n        \n        ```tsx\n        class QueueNode {\n          value: string;\n          next: QueueNode | null;\n        \n          constructor(value: string) {\n            this.value = value;\n            this.next = null;\n          }\n        }\n        \n        class Queue {\n          front: QueueNode | null;\n          back: QueueNode | null;\n          size: number;\n        \n          constructor() {\n            this.front = null;\n            this.back = null;\n            this.size = 0;\n          }\n        \n          enque(value: string): void {\n            const newNode = new QueueNode(value);\n            if (this.size === 0) {\n              this.front = newNode;\n              this.back = newNode;\n            } else {\n              this.back!.next = newNode; // Use non-null assertion\n              this.back = newNode;\n            }\n            this.size++;\n          }\n        \n          deque(): string | null {\n            if (this.size === 0) {\n              return null;\n            }\n        \n            const node = this.front; // Store the front node to return its value\n            if (this.front !== null) { // Check if front is not null\n              this.front = this.front.next;\n            }\n            if (this.size === 1) {\n              this.back = null;\n            }\n            this.size--;\n        \n            return node!.value; // Use non-null assertion since node is not null here\n          }\n        }\n        \n        const queue: Queue = new Queue();\n        queue.enque(\"a\");\n        queue.enque(\"b\");\n        queue.enque(\"c\");\n        queue.enque(\"d\");\n        console.log(queue);\n        console.log(queue.front?.value);\n        console.log(queue.back?.value);\n        console.log(queue.deque());\n        queue.deque();\n        queue.deque();\n        queue.deque();\n        console.log(queue);\n        \n        ```\n        \n        1. Valid Paranthesis\n        \n        ```tsx\n        let str: string = \"(])\";\n        console.log(checkValidParenthesis(str));\n        \n        function checkValidParenthesis(str: string): boolean {\n          let n: number = str.length;\n          let stack: string[] = [];\n          \n          for (let i: number = 0; i \u003c n; i++) {\n            if (str[i] === \"(\" || str[i] === \"[\" || str[i] === \"{\") {\n              stack.push(str[i]);\n            } else {\n              if (stack.length === 0) return false;\n              let ch: string = stack[stack.length - 1];\n              if (\n                (str[i] === \")\" \u0026\u0026 ch === \"(\") ||\n                (str[i] === \"}\" \u0026\u0026 ch === \"{\") ||\n                (str[i] === \"]\" \u0026\u0026 ch === \"[\")\n              ) {\n                stack.pop();\n              } else {\n                return false;\n              }\n            }\n          }\n          return stack.length === 0;\n        }\n        ```\n        \n        1. Stack Using Queue\n        \n        ```tsx\n        class Stack {\n          private queue1: number[];\n          private queue2: number[];\n        \n          constructor() {\n            this.queue1 = [];\n            this.queue2 = [];\n          }\n        \n          // Adds a new element to the stack\n          push(value: number): void {\n            this.queue1.push(value);\n          }\n        \n          // Removes the top element from the stack and returns it\n          pop(): number | null {\n            if (this.queue1.length === 0) return null;\n        \n            // Transfer elements from queue1 to queue2, leaving only the last one\n            while (this.queue1.length \u003e 1) {\n              this.queue2.push(this.queue1.shift() as number);\n            }\n        \n            // The last element in queue1 is the top element of the stack\n            const poppedItem = this.queue1.shift() as number;\n        \n            // Swap queues to keep queue1 as the main queue\n            [this.queue1, this.queue2] = [this.queue2, this.queue1];\n            return poppedItem;\n          }\n        \n          // Returns the top element of the stack without removing it\n          top(): number | null {\n            if (this.queue1.length === 0) return null;\n        \n            // Transfer elements from queue1 to queue2, leaving only the last one\n            while (this.queue1.length \u003e 1) {\n              this.queue2.push(this.queue1.shift() as number);\n            }\n        \n            // Get the top item and add it back to queue2\n            const topItem = this.queue1.shift() as number;\n            this.queue2.push(topItem);\n        \n            // Swap queues to keep queue1 as the main queue\n            [this.queue1, this.queue2] = [this.queue2, this.queue1];\n            return topItem;\n          }\n        \n          // Checks if the stack is empty\n          isEmpty(): boolean {\n            return this.queue1.length === 0;\n          }\n        \n          // Returns the size of the stack\n          size(): number {\n            return this.queue1.length;\n          }\n        }\n        \n        // Testing the Stack implementation\n        const stack: Stack = new Stack();\n        stack.push(1);\n        stack.push(2);\n        stack.push(3);\n        \n        console.log(stack.pop()); // Output: 3\n        console.log(stack.top()); // Output: 2\n        console.log(stack.pop()); // Output: 2\n        console.log(stack.isEmpty()); // Output: false\n        console.log(stack.size()); // Output: 1\n        \n        ```\n        \n        1. Queue Using Stack\n        \n        ```jsx\n        class Queue{\n            private stack1:number[];\n            private stack2: number[];\n            constructor(){\n                this.stack1=[];\n                this.stack2=[];\n            }\n            enqueue(value:number):void{\n                this.stack1.push(value);\n            }\n            dequeue():number|null{\n                if(this.stack2.length===0){\n                    if(this.stack1.length===0){\n                        return null;\n                    }\n                    while(this.stack1.length\u003e0){\n                        this.stack2.push(this.stack1.pop() as number);\n                    }\n                }\n                return this.stack2.pop() || null;\n            }\n            front():number | null{\n                if(this.stack2.length===0){\n                    if(this.stack1.length===0){\n                        return null;\n                    }\n                    while(this.stack1.length\u003e0){\n                        this.stack2.push(this.stack1.pop()as number);\n                    }\n                }\n                return this.stack2[this.stack2.length-1]||null;\n            }\n        isEmpty():boolean{\n            return this.stack1.length===0\u0026\u0026this.stack2.length===0;\n        }\n        size():number{\n            return this.stack1.length+this.stack2.length;\n        }\n        }\n        // Example usage:\n        const queue = new Queue();\n        queue.enqueue(1);\n        queue.enqueue(2);\n        queue.enqueue(3);\n        \n        console.log(queue.dequeue()); // 1\n        console.log(queue.front()); // 2\n        console.log(queue.dequeue()); // 2\n        console.log(queue.isEmpty()); // false\n        console.log(queue.size()); // 1\n        ```\n        \n        1. Min Stack\n        \n        ```jsx\n        class MinStack{\n            private stack:number[];\n            private minStack:number[];\n            constructor(){\n                this.stack=[];\n                this.minStack=[];\n            }\n        push(val:number):void{\n            this.stack.push(val);\n            if(this.minStack.length===0 || val\u003c=this.minStack[this.minStack.length-1]){\n                this.minStack.push(val);\n            }\n        }\n        pop():void{\n            if(this.stack.length===0)return;\n            if(this.stack[this.stack.length-1]===this.minStack[this.minStack.length-1]){\n                this.minStack.pop();\n            }\n            this.stack.pop();\n        }\n        top():number|null{\n            if(this.stack.length===0) return null;\n            return this.stack[this.stack.length-1];\n        }\n        getMin():number|null{\n            if(this.minStack.length===0) return null;\n            return this.minStack[this.minStack.length-1];\n        }\n        }\n        const minStack = new MinStack();\n        minStack.push(-2);\n        minStack.push(0);\n        minStack.push(-3);\n        console.log(minStack.getMin()); // Output: -3\n        minStack.pop();\n        console.log(minStack.top());    // Output: 0\n        console.log(minStack.getMin()); // Output: -2\n        ```\n        \n        1. Next Greater Element\n        \n        ```jsx\n        const nums1: number[] = [4, 1, 2];\n        const nums2: number[] = [1, 3, 4, 2];\n        const result = nextGreaterElement(nums1, nums2);\n        console.log(result);\n        \n        function nextGreaterElement(nums1: number[], nums2: number[]): number[] {\n            const nextGreater = new Map\u003cnumber, number\u003e();\n            const stack: number[] = [];\n        \n            for (const num of nums2) {\n                while (stack.length \u003e 0 \u0026\u0026 stack[stack.length - 1] \u003c num) {\n                    nextGreater.set(stack.pop() as number, num);\n                }\n                stack.push(num);\n            }\n        \n            const result: number[] = [];\n            for (const num1 of nums1) {\n                result.push(nextGreater.has(num1) ? nextGreater.get(num1)! : -1);\n            }\n            return result;\n        }\n        \n        ```\n        \n        1. Next Smallest Element\n        \n        ```jsx\n        let arr:number[]=[4,5,2,10,8];\n        console.log(nextSmallerElement(arr));\n        function nextSmallerElement(arr:number[]){\n            let n:number=arr.length;\n            let stack:number[]=[];\n            let ans:number[]=[];\n            ans[0]=-1;\n        for(let i=0;i\u003cn;i++){\n            while(stack.length\u003e0 \u0026\u0026 stack[stack.length-1]\u003e=arr[i]){\n                stack.pop() as number;\n            }\n            if(stack.length===0){\n                ans[i]=-1;\n            }\n            else{\n                ans[i]=stack[stack.length-1];\n            }\n            stack.push(arr[i]);\n        }\n        return ans;\n        }\n        ```\n        \n        1. Trapping Rain Water\n        \n        ```jsx\n        let arr: number[] = [0, 1, 2, 1, 4, 3, 3, 2];\n        let n: number = arr.length;\n        console.log(trapWater(arr, n));\n        \n        function trapWater(arr: number[], n: number): number {\n            let left = 0, right = n - 1;\n            let waterTrapped = 0;\n            let maxLeft = 0, maxRight = 0;\n        \n            while (left \u003c= right) {\n                if (arr[left] \u003c= arr[right]) {\n                    if (arr[left] \u003e= maxLeft) {\n                        maxLeft = arr[left];\n                    } else {\n                        waterTrapped += maxLeft - arr[left];\n                    }\n                    left++;\n                } else {\n                    if (arr[right] \u003e= maxRight) {\n                        maxRight = arr[right];\n                    } else {\n                        waterTrapped += maxRight - arr[right];\n                    }\n                    right--;\n                }\n            }\n            return waterTrapped;\n        }\n        \n        ```\n        \n        1. Sum of Sub Array Min\n        \n        ```jsx\n        function subArrayMinOptimal(arr: number[], n: number): number {\n          const mod = 10 ** 9 + 7;\n          const left: number[] = new Array(n);\n          const right: number[] = new Array(n);\n          const stack: number[] = [];\n        \n          // Calculate the left boundary for each element\n          for (let i = 0; i \u003c n; i++) {\n            while (stack.length \u003e 0 \u0026\u0026 arr[stack[stack.length - 1]] \u003e arr[i]) {\n              stack.pop();\n            }\n            left[i] = stack.length === 0 ? -1 : stack[stack.length - 1];\n            stack.push(i);\n          }\n        \n          stack.length = 0; // Reset stack for right boundary calculation\n        \n          // Calculate the right boundary for each element\n          for (let i = n - 1; i \u003e= 0; i--) {\n            while (stack.length !== 0 \u0026\u0026 arr[stack[stack.length - 1]] \u003e= arr[i]) {\n              stack.pop();\n            }\n            right[i] = stack.length === 0 ? n : stack[stack.length - 1];\n            stack.push(i);\n          }\n        \n          let sum = 0;\n        \n          // Calculate the sum of subarray minimums\n          for (let i = 0; i \u003c n; i++) {\n            sum = (sum + (i - left[i]) * (right[i] - i) * arr[i]) % mod;\n          }\n        \n          return sum;\n        }\n        \n        // Example usage\n        const arr: number[] = [3, 1, 2, 4];\n        const n: number = arr.length;\n        console.log(subArrayMinOptimal(arr, n)); // Output: 17\n        \n        ```\n        \n        1. Histogram\n        \n        ```jsx\n        let arr:number[] = [2, 1, 5, 6, 2, 3, 1];\n        let n:number = arr.length;\n        console.log(largestArea(arr, n));\n        \n        function largestArea(arr:number[],n:number){\n            let stack:number[]=[];\n            let leftSmall:number[]=new Array(n);\n            let rightSmall:number[]=new Array(n);\n            for(let i=0;i\u003cn;i++){\n          while (stack.length != 0 \u0026\u0026 arr[stack[stack.length - 1]] \u003e= arr[i]) {\n              stack.pop();\n            }\n            if (stack.length == 0) {\n              leftSmall[i] = 0;\n            } else {\n              leftSmall[i] = stack[stack.length - 1] + 1;\n            }\n            stack.push(i);\n          }\n        \n          while (stack.length !== 0) {\n            stack.pop();\n          }\n        \n          for (let i = n - 1; i \u003e= 0; i--) {\n            while (stack.length !== 0 \u0026\u0026 arr[stack[stack.length - 1]] \u003e= arr[i]) {\n              stack.pop();\n            }\n            if (stack.length == 0) {\n              rightSmall[i] = n - 1;\n            } else {\n              rightSmall[i] = stack[stack.length - 1] - 1;\n            }\n            stack.push(i);\n          }\n        \n          let maxA = 0;\n          for (let i = 0; i \u003c n; i++) {\n            maxA = Math.max(maxA, arr[i] * (rightSmall[i] - leftSmall[i] + 1));\n          }\n          return maxA;\n        }\n        ```\n        \n        1. Asteroid Collision\n        \n        ```jsx\n        function asteroidCollision(asteroids: number[]): number[] {\n          const stack: number[] = [];\n        \n          for (let i = 0; i \u003c asteroids.length; i++) {\n            let add = true;\n            while (stack.length !== 0 \u0026\u0026 asteroids[i] \u003c 0 \u0026\u0026 stack[stack.length - 1] \u003e 0) {\n              if (Math.abs(asteroids[i]) \u003e Math.abs(stack[stack.length - 1])) {\n                stack.pop();\n              } else if (Math.abs(asteroids[i]) === Math.abs(stack[stack.length - 1])) {\n                stack.pop();\n                add = false;\n                break;\n              } else {\n                add = false;\n                break;\n              }\n            }\n            if (add) stack.push(asteroids[i]);\n          }\n          return stack;\n        }\n        \n        // Example usage\n        let asteroids: number[] = [5, 10, -5];\n        console.log(asteroidCollision(asteroids)); // Output: [5, 10]\n        \n        ```\n        \n        1. Sum of Sub Arrays Ranges\n        \n        ```jsx\n        function subArrayRanges(arr: number[], n: number): number {\n          let total = 0;\n        \n          for (let i = 0; i \u003c n; i++) {\n            let min = arr[i];\n            let max = arr[i];\n            for (let j = i; j \u003c n; j++) {\n              min = Math.min(min, arr[j]);\n              max = Math.max(max, arr[j]);\n              total += max - min;\n            }\n          }\n          return total;\n        }\n        \n        function subArrayRangesOptimal(arr: number[], n: number): number {\n          const mod = 10 ** 9 + 7;\n          let result = 0;\n          let stack: number[] = [];\n        \n          const left: number[] = new Array(n).fill(0);\n          const maxLeft: number[] = new Array(n).fill(0);\n          const right: number[] = new Array(n).fill(0);\n          const maxRight: number[] = new Array(n).fill(0);\n        \n          // Calculate left distances for minimums\n          for (let i = 0; i \u003c n; i++) {\n            while (stack.length \u003e 0 \u0026\u0026 arr[i] \u003c arr[stack[stack.length - 1]]) {\n              stack.pop();\n            }\n            left[i] = stack.length === 0 ? i + 1 : i - stack[stack.length - 1];\n            stack.push(i);\n          }\n        \n          stack = [];\n        \n          // Calculate right distances for minimums\n          for (let i = n - 1; i \u003e= 0; i--) {\n            while (stack.length \u003e 0 \u0026\u0026 arr[i] \u003c= arr[stack[stack.length - 1]]) {\n              stack.po","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdheerajjha451%2Fdsa_typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdheerajjha451%2Fdsa_typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdheerajjha451%2Fdsa_typescript/lists"}