Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
280 lines (253 loc) · 17.4 KB
/
Copy pathindex.js
File metadata and controls
280 lines (253 loc) · 17.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/env node
/**
* ============================================================================
* JAVASCRIPT DSA LEARNING - CHALLENGE RUNNER
* ============================================================================
*
* This is your coding workstation!
*
* HOW TO USE:
*
* 1. OPTION A - Run specific challenge tests:
* Simply uncomment one of the test sections below
*
* 2. OPTION B - Run all array tests:
* Uncomment the "runAllTests();" line at the bottom
*
* 3. OPTION C - Implement a challenge here:
* Import your challenge function and test it manually
*
* 4. To run: npm start
*
* ============================================================================
*/
// ============================================================================
// IMPORT TEST SUITES - Uncomment to run tests for specific data structures
// ============================================================================
// import { runAllTests as runArrayTests } from './tests/array.test.js';
// import { runAllTests as runHashTableTests } from './tests/hash-table.test.js'; // Coming soon
// import { runAllTests as runLinkedListTests } from './tests/linked-list.test.js'; // Coming soon
// ============================================================================
// IMPORT YOUR CHALLENGE IMPLEMENTATIONS HERE
// ============================================================================
// Arrays - Uncomment as you implement:
// import { findMaximum } from './challenges/array-challenges/01-find-maximum.js';
// import { countOccurrences } from './challenges/array-challenges/02-count-occurrences.js';
// import { removeElement } from './challenges/array-challenges/03-remove-element.js';
// import { mergeSortedArrays } from './challenges/array-challenges/04-merge-sorted-arrays.js';
// import { rotateArray } from './challenges/array-challenges/05-rotate-array.js';
// import { twoSum } from './challenges/array-challenges/06-two-sum.js';
// Hash Tables - Coming soon
// ...
// Linked Lists - Coming soon
// ...
// ============================================================================
// SETUP & EXECUTION
// ============================================================================
console.log(`
╔════════════════════════════════════════════════════════════════════════════╗
║ JAVASCRIPT DSA LEARNING ENVIRONMENT ║
║ ║
║ Purpose: Practice data structures and algorithms with strict Big O ║
║ complexity requirements and automated testing ║
╚════════════════════════════════════════════════════════════════════════════╝
`);
// ============================================================================
// HOWTO: WORKING ON CHALLENGES
// ============================================================================
console.log(`
┌─ HOW TO USE THIS ENVIRONMENT ─────────────────────────────────────────────┐
│ │
│ WORKFLOW: │
│ ───────── │
│ 1. Open a challenge file in challenges/[structure]-challenges/ │
│ 2. Implement the solution function (replacing the "throw" statement) │
│ 3. Import the function at top of this file (uncomment import) │
│ 4. Run test command: npm start │
│ 5. Read test results carefully - they include hints! │
│ 6. Fix your solution and repeat │
│ │
│ IMPORTANT NOTES: │
│ ──────────────── │
│ ✓ Tests check time complexity - O(n²) solutions will FAIL │
│ ✓ Tests check space complexity - Extra arrays will cause FAIL │
│ ✓ Must implement exactly as specified in challenge files │
│ ✓ Focus on algorithm efficiency, not just correctness │
│ │
│ INCLUDED FEATURES: │
│ ────────────────── │
│ • Comprehensive test suite for each challenge │
│ • Big O complexity validation │
│ • Helpful clues when tests fail │
│ • Performance timing analysis │
│ • Input/output verification │
│ │
└───────────────────────────────────────────────────────────────────────────┘
`);
// ============================================================================
// MANUAL TESTING AREA (Optional)
// ============================================================================
/**
* If you want to manually test a challenge, do it here.
* Example:
*
* console.log("Testing findMaximum:");
* console.log(findMaximum([3, 7, 2, 8, 1])); // Should print 8
*/
// ============================================================================
// AUTO TEST RUNNER
// ============================================================================
/**
* Uncomment the test runner for the data structure you're working on:
*
* - runArrayTests() - Run all array challenges
* - runHashTableTests() - Run all hash table challenges (coming soon)
* - runLinkedListTests() - Run all linked list challenges (coming soon)
*
* Each will:
* - Test correctness of your implementations
* - Verify Big O time complexity
* - Verify Big O space complexity
* - Provide hints if tests fail
*/
// runArrayTests(); // Currently testing arrays
// ---------------------------------------------------------------------------
// NEW: Per-challenge test helpers
// You can run a single array challenge from npm using the scripts added to
// package.json (example: `npm run test:array-1` runs challenge 01-find-maximum).
// The package.json scripts import small exported helpers from
// `tests/array.test.js` (e.g. `runFindMaxTests`). This avoids creating new
// files and keeps single-test execution lightweight.
// ---------------------------------------------------------------------------
// Examples (from the shell):
// npm run test:array # run all array tests
// npm run test:array-1 # run challenge 01 - find maximum
// npm run test:array-2 # run challenge 02 - count occurrences
// npm run test:array-3 # run challenge 03 - remove element
// npm run test:array-4 # run challenge 04 - merge sorted arrays
// npm run test:array-5 # run challenge 05 - rotate array
// npm run test:array-6 # run challenge 06 - two-sum
// ============================================================================
// CHALLENGE SELECTION (Uncomment to run specific challenge tests)
// ============================================================================
/**
* To run tests for a specific challenge, create a test runner:
*
* Example:
* const tester = new ChallengeTest('Challenge 1: Find Maximum');
* tester.test('Basic case', () => {
* const result = findMaximum([3, 7, 2, 8, 1]);
* assert(result === 8, `Expected 8, got ${result}`);
* });
* tester.run();
*/
// ============================================================================
// SUGGESTED LEARNING ORDER
// ============================================================================
console.log(`
┌─ CURRENT FOCUS: ARRAYS ───────────────────────────────────────────────────┐
│ │
│ ARRAYS - 6 Challenges (4-8 hours total) │
│ ──────────────────────────────────────────────────────────────── │
│ 1. Find Maximum (01-find-maximum.js) │
│ • Easy - Linear scan and comparison │
│ • Time: O(n), Space: O(1) │
│ │
│ 2. Count Occurrences (02-count-occurrences.js) │
│ • Easy - Counting pattern │
│ • Time: O(n), Space: O(1) │
│ │
│ 3. Remove Element (03-remove-element.js) │
│ • Medium - Two-pointer technique (★ Important!) │
│ • Time: O(n), Space: O(1) │
│ │
│ 4. Merge Sorted Arrays (04-merge-sorted-arrays.js) │
│ • Medium - Merge operation (foundation of Merge Sort) │
│ • Time: O(n+m), Space: O(n+m) │
│ │
│ 5. Rotate Array (05-rotate-array.js) │
│ • Medium - In-place rotation with reversal │
│ • Time: O(n), Space: O(1) │
│ │
│ 6. Two Sum (06-two-sum.js) │
│ • Medium - Hash map approach (★★ Critical for interviews!) │
│ • Time: O(n), Space: O(n) │
│ │
│ See docs/array-reference-links.md for detailed information │
│ │
│ NEXT DATA STRUCTURES (Coming Soon): │
│ • Hash Tables - O(1) lookups and insertions │
│ • Linked Lists - O(1) middle operations │
│ • Stacks & Queues - LIFO and FIFO structures │
│ │
└───────────────────────────────────────────────────────────────────────────┘
`);
// ============================================================================
// TESTING FRAMEWORK EXPLANATION
// ============================================================================
console.log(`
┌─ WHAT TO EXPECT FROM TESTS ────────────────────────────────────────────────┐
│ │
│ Each test will verify: │
│ │
│ ✓ CORRECTNESS │
│ - Does your solution produce the right output? │
│ - Are edge cases handled? │
│ │
│ ✓ TIME COMPLEXITY │
│ - Is your solution fast enough? │
│ - Tests with large inputs to catch O(n²) vs O(n) │
│ - Provides hints if you're too slow │
│ │
│ ✓ SPACE COMPLEXITY │
│ - Are you using extra arrays/objects when not needed? │
│ - Some challenges require O(1) space (in-place modification) │
│ - Tests will fail if you create unnecessary data structures │
│ │
│ ✓ ALGORITHM APPROACH │
│ - Certain problems REQUIRE specific algorithms │
│ - Example: Two Sum MUST use hash map, not nested loops │
│ - Tests will catch and reject non-optimal approaches │
│ │
│ WHEN TESTS FAIL: │
│ → Read the error message carefully │
│ → Look for the 💡 HINT section │
│ → Hints explain what's wrong and how to fix it │
│ → Check docs/reference-links.md for learning resources │
│ │
└────────────────────────────────────────────────────────────────────────────┘
`);
// ============================================================================
// NEXT STEPS
// ============================================================================
console.log(`
┌─ YOUR NEXT STEPS ─────────────────────────────────────────────────────────┐
│ │
│ GETTING STARTED: │
│ │
│ 1. Choose your data structure (currently: Arrays) │
│ → Read: src/data-structures/arrays.js │
│ → Understand operations and Big O complexity │
│ │
│ 2. Start with the first challenge │
│ → Open: challenges/array-challenges/01-find-maximum.js │
│ → Implement the solution function │
│ → Uncomment the import at top of this file │
│ → Run: npm start │
│ │
│ 3. Check results and iterate │
│ → If tests pass ✓ → Move to next challenge │
│ → If tests fail ✗ → Read hints and fix │
│ │
│ 4. Deep dive into resources │
│ → Check: docs/array-reference-links.md for detailed references │
│ → Review: docs/reference-links.md for general DSA resources │
│ → Practice similar problems on LeetCode │
│ │
│ 5. After mastering one data structure │
│ → Move to the next (Hash Tables, Linked Lists, etc.) │
│ → Build on previous knowledge │
│ │
└────────────────────────────────────────────────────────────────────────────┘
`);
console.log('\n' + '═'.repeat(80) + '\n');