{"id": "dsa-v01-train-001", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "01_foundations", "subtopic": "big_o_choice", "language": "javascript", "instruction": "Choose between O(n), O(n log n), and O(n²) approaches from constraints.", "concept": "Explain how constraints influence algorithm selection. Given n up to 10^5, prefer an approach around O(n log n) or better over O(n²).", "solution": {"language": "javascript", "code": "// Language-agnostic reasoning is primary; no single implementation is required for this concept.", "explanation": "Explain how constraints influence algorithm selection. Given n up to 10^5, prefer an approach around O(n log n) or better over O(n²)."}, "tests": [], "edge_cases": [], "complexity": "O(n log n) or better for n up to 10^5; avoid O(n²) approaches.", "tags": ["dsa", "01_foundations", "concept"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-002", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "01_foundations", "subtopic": "dry_run", "language": "javascript", "instruction": "Trace a loop and determine its output and time complexity.", "concept": "A dry run tracks state changes step by step; count the loop iterations and simplify the growth rate.", "solution": {"language": "javascript", "code": "function sumToN(n) { let s = 0; for (let i = 1; i <= n; i++) s += i; return s; }", "explanation": "A dry run tracks state changes step by step; count the loop iterations and simplify the growth rate."}, "tests": [], "edge_cases": [], "complexity": "O(n)", "tags": ["dsa", "01_foundations", "code_tracing"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-004", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "02_arrays", "subtopic": "rotate_array", "language": "javascript", "instruction": "Rotate an array to the right by k positions.", "concept": "Normalize k and use the reversal technique.", "solution": {"language": "javascript", "code": "function rotateRight(arr, k) { const n = arr.length; if (!n) return arr; k %= n; const rev = (l,r) => { while (larr.length) return null; let s=0; for(let i=0;ii.", "solution": {"language": "javascript", "code": "function transpose(A){ for(let i=0;ii."}, "tests": [], "edge_cases": [], "complexity": "O(n²) time, O(1) extra space for square matrix", "tags": ["dsa", "02_arrays", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-013", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "02_arrays", "subtopic": "rotate_matrix_90", "language": "javascript", "instruction": "Rotate a square matrix 90 degrees clockwise.", "concept": "Transpose the matrix, then reverse each row.", "solution": {"language": "javascript", "code": "function rotate90(A){ transpose(A); for(const row of A) row.reverse(); return A; }", "explanation": "Transpose the matrix, then reverse each row."}, "tests": [], "edge_cases": [], "complexity": "O(n²) time, O(1) extra space for square matrix", "tags": ["dsa", "02_arrays", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-014", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "03_bit_manipulation", "subtopic": "check_ith_bit", "language": "javascript", "instruction": "Check whether bit i is set.", "concept": "Mask the number with 1 shifted left by i and test whether the result is nonzero.", "solution": {"language": "javascript", "code": "function isSet(n,i){ return (n & (1 << i)) !== 0; }", "explanation": "Mask the number with 1 shifted left by i and test whether the result is nonzero."}, "tests": [], "edge_cases": [], "complexity": "O(1)", "tags": ["dsa", "03_bit_manipulation", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-015", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "03_bit_manipulation", "subtopic": "set_ith_bit", "language": "javascript", "instruction": "Set bit i to 1.", "concept": "OR the number with a mask containing a 1 at bit i.", "solution": {"language": "javascript", "code": "function setBit(n,i){ return n | (1 << i); }", "explanation": "OR the number with a mask containing a 1 at bit i."}, "tests": [], "edge_cases": [], "complexity": "O(1)", "tags": ["dsa", "03_bit_manipulation", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-017", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "03_bit_manipulation", "subtopic": "unique_element", "language": "javascript", "instruction": "Find the element occurring once when every other element occurs twice.", "concept": "XOR equal pairs cancel and the remaining value is the unique element.", "solution": {"language": "javascript", "code": "function singleNumber(arr){ let x=0; for(const v of arr) x^=v; return x; }", "explanation": "XOR equal pairs cancel and the remaining value is the unique element."}, "tests": [], "edge_cases": [], "complexity": "O(n) time, O(1) extra space", "tags": ["dsa", "03_bit_manipulation", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-018", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "04_recursion", "subtopic": "factorial_recursive", "language": "javascript", "instruction": "Compute factorial recursively.", "concept": "Base case is 0 or 1; otherwise n * factorial(n-1).", "solution": {"language": "javascript", "code": "function factorial(n){ if(n<=1) return 1; return n*factorial(n-1); }", "explanation": "Base case is 0 or 1; otherwise n * factorial(n-1)."}, "tests": [], "edge_cases": [], "complexity": "O(n) time, O(n) call-stack space", "tags": ["dsa", "04_recursion", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-019", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "04_recursion", "subtopic": "fibonacci_recursive", "language": "javascript", "instruction": "Compute Fibonacci recursively and identify the repeated subproblem.", "concept": "The direct recursive definition repeats subproblems and therefore grows exponentially; it is useful as a recursion/DP introduction.", "solution": {"language": "javascript", "code": "function fib(n){ if(n<=1) return n; return fib(n-1)+fib(n-2); }", "explanation": "The direct recursive definition repeats subproblems and therefore grows exponentially; it is useful as a recursion/DP introduction."}, "tests": [], "edge_cases": [], "complexity": "Exponential time for the naive recursion, O(n) stack", "tags": ["dsa", "04_recursion", "concept_plus_code"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-022", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "05_math", "subtopic": "mod_pair_count", "language": "javascript", "instruction": "Count pairs whose sum is divisible by m.", "concept": "Track remainders. A remainder r pairs with (m-r)%m; handle remainder 0 separately.", "solution": {"language": "javascript", "code": "function countPairsDivisibleByM(arr,m){ const freq=new Array(m).fill(0); let ans=0; for(const x of arr){ const r=((x%m)+m)%m; ans += freq[(m-r)%m]; freq[r]++; } return ans; }", "explanation": "Track remainders. A remainder r pairs with (m-r)%m; handle remainder 0 separately."}, "tests": [], "edge_cases": [], "complexity": "O(n+m) time, O(m) space", "tags": ["dsa", "05_math", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-023", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "05_math", "subtopic": "sieve", "language": "javascript", "instruction": "Generate all primes up to n with the Sieve of Eratosthenes.", "concept": "Mark multiples starting from p² for each prime p up to sqrt(n).", "solution": {"language": "javascript", "code": "function sieve(n){ const prime=Array(n+1).fill(true); if(n>=0) prime[0]=false; if(n>=1) prime[1]=false; for(let p=2;p*p<=n;p++) if(prime[p]) for(let x=p*p;x<=n;x+=p) prime[x]=false; return prime.map((v,i)=>v?i:null).filter(v=>v!==null); }", "explanation": "Mark multiples starting from p² for each prime p up to sqrt(n)."}, "tests": [], "edge_cases": [], "complexity": "O(n log log n) time, O(n) space", "tags": ["dsa", "05_math", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-024", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "06_hashing", "subtopic": "frequency_map", "language": "javascript", "instruction": "Count the frequency of each value.", "concept": "Store counts in a Map and update once per element.", "solution": {"language": "javascript", "code": "function frequencyMap(arr){ const m=new Map(); for(const x of arr) m.set(x,(m.get(x)||0)+1); return m; }", "explanation": "Store counts in a Map and update once per element."}, "tests": [], "edge_cases": [], "complexity": "Expected O(n) time, O(u) space", "tags": ["dsa", "06_hashing", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-026", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "06_hashing", "subtopic": "longest_unique_substring", "language": "javascript", "instruction": "Find the length of the longest substring without repeating characters.", "concept": "Use a sliding window and a map of the most recent index of each character.", "solution": {"language": "javascript", "code": "function lengthOfLongestSubstring(s){ const last=new Map(); let left=0,best=0; for(let r=0;rb.length) return medianTwoSorted(b,a); const n=a.length,m=b.length; let lo=0,hi=n; while(lo<=hi){ const i=Math.floor((lo+hi)/2), j=Math.floor((n+m+1)/2)-i; const al=i? a[i-1]:-Infinity, ar=ibr) hi=i-1; else lo=i+1; } return null; }", "explanation": "Use the partition-based binary-search formulation on the smaller array."}, "tests": [], "edge_cases": [], "complexity": "O(log min(n,m)) time, O(1) extra space", "tags": ["dsa", "08_searching", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-035", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "09_linked_lists", "subtopic": "reverse_list", "language": "javascript", "instruction": "Reverse a singly linked list.", "concept": "Iteratively redirect each next pointer to the previous node.", "solution": {"language": "javascript", "code": "function reverseList(head){ let prev=null,cur=head; while(cur){ const next=cur.next; cur.next=prev; prev=cur; cur=next; } return prev; }", "explanation": "Iteratively redirect each next pointer to the previous node."}, "tests": [], "edge_cases": [], "complexity": "O(n) time, O(1) space", "tags": ["dsa", "09_linked_lists", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-036", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "09_linked_lists", "subtopic": "doubly_insert_before_tail", "language": "javascript", "instruction": "Insert a node before the tail in a doubly linked list.", "concept": "Update both next and prev links around the insertion point.", "solution": {"language": "javascript", "code": "function insertBeforeTail(tail,value){ const node={value,prev:tail.prev,next:tail}; if(tail.prev) tail.prev.next=node; tail.prev=node; return node; }", "explanation": "Update both next and prev links around the insertion point."}, "tests": [], "edge_cases": [], "complexity": "O(1) time when tail is available", "tags": ["dsa", "09_linked_lists", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-038", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "10_stacks", "subtopic": "postfix_evaluation", "language": "javascript", "instruction": "Evaluate a postfix expression.", "concept": "Push operands; for an operator, pop the right and left operands, apply the operator, and push the result.", "solution": {"language": "javascript", "code": "function evalPostfix(tokens){ const st=[]; for(const t of tokens){ if(!['+','-','*','/'].includes(t)) st.push(Number(t)); else { const b=st.pop(),a=st.pop(); if(t==='+')st.push(a+b); if(t==='-')st.push(a-b); if(t==='*')st.push(a*b); if(t==='/')st.push(a/b); } } return st[0]; }", "explanation": "Push operands; for an operator, pop the right and left operands, apply the operator, and push the result."}, "tests": [], "edge_cases": [], "complexity": "O(n) time, O(n) space", "tags": ["dsa", "10_stacks", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-039", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "10_stacks", "subtopic": "nearest_smaller_left", "language": "javascript", "instruction": "For each array element, find the nearest smaller element to its left.", "concept": "Maintain a monotonic increasing stack and pop elements that cannot be the nearest smaller candidate.", "solution": {"language": "javascript", "code": "function nearestSmallerLeft(a){ const st=[],out=[]; for(const x of a){ while(st.length&&st[st.length-1]>=x)st.pop(); out.push(st.length?st[st.length-1]:-1); st.push(x); } return out; }", "explanation": "Maintain a monotonic increasing stack and pop elements that cannot be the nearest smaller candidate."}, "tests": [], "edge_cases": [], "complexity": "O(n) time, O(n) space", "tags": ["dsa", "10_stacks", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-041", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "11_queues", "subtopic": "bfs_queue_reasoning", "language": "javascript", "instruction": "Why does BFS use a queue?", "concept": "BFS processes vertices in the order they are discovered, so a FIFO queue preserves increasing distance layers in an unweighted graph.", "solution": {"language": "javascript", "code": "function bfs(graph,start){ const q=[start],seen=new Set([start]),order=[]; for(let h=0;h=hi)return false;return dfs(n.left,lo,n.val)&&dfs(n.right,n.val,hi);} return dfs(root,-Infinity,Infinity); }", "explanation": "Carry lower and upper bounds so every node respects all ancestor constraints."}, "tests": [], "edge_cases": [], "complexity": "O(n) time, O(h) stack", "tags": ["dsa", "12_trees_bst", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-044", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "12_trees_bst", "subtopic": "kth_smallest_bst", "language": "javascript", "instruction": "Find the kth smallest value in a BST.", "concept": "Inorder traversal of a BST visits values in sorted order; stop after visiting k nodes.", "solution": {"language": "javascript", "code": "function kthSmallest(root,k){ const st=[]; let n=root; while(true){ while(n){st.push(n);n=n.left;} n=st.pop(); if(--k===0)return n.val; n=n.right; } }", "explanation": "Inorder traversal of a BST visits values in sorted order; stop after visiting k nodes."}, "tests": [], "edge_cases": [], "complexity": "O(h+k) typical, O(h) space", "tags": ["dsa", "12_trees_bst", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-045", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "12_trees_bst", "subtopic": "lca_bst", "language": "javascript", "instruction": "Find the lowest common ancestor of two nodes in a BST.", "concept": "Use the BST ordering: if both targets are smaller go left; if both larger go right; otherwise current node is the split point.", "solution": {"language": "javascript", "code": "function lcaBST(root,p,q){ let n=root; while(n){ if(pn.val&&q>n.val)n=n.right; else return n; } return null; }", "explanation": "Use the BST ordering: if both targets are smaller go left; if both larger go right; otherwise current node is the split point."}, "tests": [], "edge_cases": [], "complexity": "O(h) time, O(1) space", "tags": ["dsa", "12_trees_bst", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-046", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "13_backtracking", "subtopic": "generate_parentheses", "language": "javascript", "instruction": "Generate all valid parentheses strings of n pairs.", "concept": "At each state, add '(' while opens remain and add ')' only when closes remain and closes are fewer than opens.", "solution": {"language": "javascript", "code": "function generateParenthesis(n){ const out=[]; function bt(s,o,c){ if(s.length===2*n){out.push(s);return;} if(o>1;if(this.a[p]<=this.a[i])break;[this.a[p],this.a[i]]=[this.a[i],this.a[p]];i=p;}} down(i){for(;;){let l=i*2+1,r=l+1,b=i;if(la-b); }", "explanation": "Insert the head of each list into a min-heap; repeatedly extract the smallest and insert its successor."}, "tests": [], "edge_cases": [], "complexity": "The source problem calls for a heap; a production implementation is O(N log k).", "tags": ["dsa", "14_heaps", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-051", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "15_greedy", "subtopic": "candy", "language": "javascript", "instruction": "Distribute minimum candies so ratings increase/decrease constraints are satisfied.", "concept": "Use two directional passes: left-to-right for increasing neighbors and right-to-left for decreasing neighbors.", "solution": {"language": "javascript", "code": "function candy(r){ const n=r.length;if(!n)return 0;const c=Array(n).fill(1);for(let i=1;ir[i-1])c[i]=c[i-1]+1;for(let i=n-2;i>=0;i--)if(r[i]>r[i+1])c[i]=Math.max(c[i],c[i+1]+1);return c.reduce((a,b)=>a+b,0); }", "explanation": "Use two directional passes: left-to-right for increasing neighbors and right-to-left for decreasing neighbors."}, "tests": [], "edge_cases": [], "complexity": "O(n) time, O(n) space", "tags": ["dsa", "15_greedy", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-052", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "16_dynamic_programming", "subtopic": "fib_dp", "language": "javascript", "instruction": "Compute Fibonacci using bottom-up DP.", "concept": "Store the two previous states rather than recomputing recursive subproblems.", "solution": {"language": "javascript", "code": "function fib(n){let a=0,b=1;for(let i=0;i=w[i];c--)dp[c]=Math.max(dp[c],dp[c-w[i]]+v[i]);return dp[C];}", "explanation": "For each item, update capacities downward so an item cannot be reused in the same iteration."}, "tests": [], "edge_cases": [], "complexity": "O(nC) time, O(C) space", "tags": ["dsa", "16_dynamic_programming", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-056", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "16_dynamic_programming", "subtopic": "coin_change_combinations", "language": "javascript", "instruction": "Count combinations of coins that make a target amount.", "concept": "Iterate coins outside and amounts upward so each combination is counted without regard to order.", "solution": {"language": "javascript", "code": "function coinChangeWays(coins,amount){const dp=Array(amount+1).fill(0);dp[0]=1;for(const c of coins)for(let x=c;x<=amount;x++)dp[x]+=dp[x-c];return dp[amount];}", "explanation": "Iterate coins outside and amounts upward so each combination is counted without regard to order."}, "tests": [], "edge_cases": [], "complexity": "O(coins*amount) time, O(amount) space", "tags": ["dsa", "16_dynamic_programming", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-058", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "16_dynamic_programming", "subtopic": "edit_distance", "language": "javascript", "instruction": "Compute Levenshtein edit distance.", "concept": "For matching characters carry the diagonal state; otherwise take one plus the minimum of insert, delete, and replace.", "solution": {"language": "javascript", "code": "function editDistance(a,b){const dp=Array.from({length:a.length+1},(_,i)=>Array.from({length:b.length+1},(_,j)=>i===0?j:j===0?i:0));for(let i=1;i<=a.length;i++)for(let j=1;j<=b.length;j++)dp[i][j]=a[i-1]===b[j-1]?dp[i-1][j-1]:1+Math.min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1]);return dp[a.length][b.length];}", "explanation": "For matching characters carry the diagonal state; otherwise take one plus the minimum of insert, delete, and replace."}, "tests": [], "edge_cases": [], "complexity": "O(mn) time, O(mn) space", "tags": ["dsa", "16_dynamic_programming", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-059", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "17_graphs", "subtopic": "dfs", "language": "javascript", "instruction": "Traverse a graph with DFS.", "concept": "Mark a vertex visited, process it, then recursively visit unvisited neighbors.", "solution": {"language": "javascript", "code": "function dfs(graph,start){const seen=new Set(),out=[];function go(u){seen.add(u);out.push(u);for(const v of graph[u]||[])if(!seen.has(v))go(v);}go(start);return out;}", "explanation": "Mark a vertex visited, process it, then recursively visit unvisited neighbors."}, "tests": [], "edge_cases": [], "complexity": "O(V+E) time, O(V) space", "tags": ["dsa", "17_graphs", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-061", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "17_graphs", "subtopic": "cycle_detection_undirected", "language": "javascript", "instruction": "Detect a cycle in an undirected graph.", "concept": "During DFS, carry the parent vertex; an already visited neighbor that is not the parent indicates a cycle.", "solution": {"language": "javascript", "code": "function hasCycle(graph){const seen=new Set();function go(u,p){seen.add(u);for(const v of graph[u]||[]){if(!seen.has(v)){if(go(v,u))return true;}else if(v!==p)return true;}return false;}for(const u in graph)if(!seen.has(u)&&go(u,null))return true;return false;}", "explanation": "During DFS, carry the parent vertex; an already visited neighbor that is not the parent indicates a cycle."}, "tests": [], "edge_cases": [], "complexity": "O(V+E) time, O(V) space", "tags": ["dsa", "17_graphs", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-062", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "17_graphs", "subtopic": "dijkstra", "language": "javascript", "instruction": "Find shortest paths from one source when edge weights are non-negative.", "concept": "Repeatedly select the unsettled vertex with smallest tentative distance and relax its outgoing edges; a heap makes selection efficient.", "solution": {"language": "javascript", "code": "function dijkstra(graph,src){const dist=new Map(Object.keys(graph).map(v=>[v,Infinity]));dist.set(String(src),0);const used=new Set();for(;;){let u=null,best=Infinity;for(const [v,d] of dist)if(!used.has(v)&&di);this.sz=Array(n).fill(1);}find(x){if(this.p[x]!==x)this.p[x]=this.find(this.p[x]);return this.p[x];}union(a,b){a=this.find(a);b=this.find(b);if(a===b)return false;if(this.sz[a]a[2]-b[2]);const d=new DSU(n),mst=[];for(const [u,v,w] of edges)if(d.union(u,v))mst.push([u,v,w]);return mst;}", "explanation": "Sort edges by weight and add an edge when DSU says it connects two different components."}, "tests": [], "edge_cases": [], "complexity": "O(E log E) dominated by sorting", "tags": ["dsa", "17_graphs", "coding_problem"], "provenance": {"source_derived": true, "transformed": true, "augmentation_type": "derived_js_implementation", "note": "The topic/problem family is grounded in the supplied DSA curriculum; the JavaScript implementation is a derived augmentation and is explicitly marked as such."}, "quality_status": "training_candidate", "split": "train"} {"id": "dsa-v01-train-065", "dataset_version": "dsa-v0.1", "record_type": "training_example", "module": "17_graphs", "subtopic": "number_of_islands", "language": "javascript", "instruction": "Count connected groups of 1s in a binary matrix.", "concept": "Scan the matrix; when an unvisited land cell is found, traverse its component and increment the island count.", "solution": {"language": "javascript", "code": "function numIslands(g){if(!g.length)return 0;const m=g.length,n=g[0].length;let c=0;const dirs=[[1,0],[-1,0],[0,1],[0,-1]];function flood(i,j){if(i<0||i>=m||j<0||j>=n||g[i][j]!=='1')return;g[i][j]='0';for(const[d1,d2]of dirs)flood(i+d1,j+d2);}for(let i=0;i