forked from Eshajha19/Algo-Infinity-Verse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
3392 lines (3029 loc) · 106 KB
/
Copy pathscript.js
File metadata and controls
3392 lines (3029 loc) · 106 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ===== QUIZ DATA =====
const quizQuestions = {
arrays: [
{
id: "arrays-1",
question:
"What is the time complexity of accessing an element in an array by index?",
options: ["O(1)", "O(n)", "O(log n)", "O(n^2)"],
correct: 0,
explanation:
"Arrays provide O(1) random access because elements are stored contiguously in memory.",
},
{
id: "arrays-2",
question: "Which of the following is NOT a characteristic of arrays?",
options: [
"Fixed size (in static arrays)",
"O(1) access time",
"Elements must be of different types",
"Contiguous memory allocation",
],
correct: 2,
explanation:
"In arrays, all elements must be of the same type. This is a key characteristic of arrays.",
},
{
id: "arrays-3",
question:
"What is the time complexity of inserting an element at the beginning of an array?",
options: ["O(1)", "O(n)", "O(log n)", "O(1)"],
correct: 1,
explanation:
"Inserting at the beginning requires shifting all existing elements, which is O(n).",
},
{
id: "arrays-4",
question:
"Which technique is commonly used to find the maximum subarray sum?",
options: [
"Binary Search",
"Kadane's Algorithm",
"Two Pointers",
"Dynamic Programming only",
],
correct: 1,
explanation:
"Kadane's Algorithm efficiently finds maximum subarray sum in O(n) time using dynamic programming.",
},
{
id: "arrays-5",
question: "What does the 'Two Sum' problem typically ask for?",
options: [
"Find two numbers that multiply to target",
"Find two numbers that sum to target",
"Find all pairs in array",
"Find the two largest numbers",
],
correct: 1,
explanation:
"Two Sum asks: given an array and target, return indices of two numbers that add up to the target.",
},
{
id: "arrays-6",
question:
"Which data structure is often used to solve Two Sum in O(n) time?",
options: ["Stack", "Queue", "Hash Map", "Linked List"],
correct: 2,
explanation:
"A hash map stores values and their indices for O(1) lookups, enabling O(n) solution.",
},
{
id: "arrays-7",
question: "What is the space complexity of a static array of size n?",
options: ["O(1)", "O(n)", "O(log n)", "O(n^2)"],
correct: 1,
explanation: "Static array uses O(n) space to store n elements.",
},
{
id: "arrays-8",
question:
"Which problem involves rotating an array elements to the right by k steps?",
options: [
"Reverse Words",
"Rotate Array",
"Shift Elements",
"Circular Buffer",
],
correct: 1,
explanation:
"The 'Rotate Array' problem asks to shift elements right by k positions in circular fashion.",
},
{
id: "arrays-9",
question:
"What is the time complexity of merging two sorted arrays of sizes m and n?",
options: ["O(1)", "O(max(m,n))", "O(m+n)", "O(m*n)"],
correct: 2,
explanation:
"Merging two sorted arrays takes O(m+n) time as each element is processed once.",
},
{
id: "arrays-10",
question:
"Which technique uses three pointers to solve 'Sort Colors' (Dutch National Flag) problem?",
options: [
"Sliding Window",
"Two Pointers",
"Three Pointers",
"Flood Fill",
],
correct: 2,
explanation:
"Dutch National Flag algorithm uses three pointers (low, mid, high) to sort 0s, 1s, and 2s in one pass.",
},
],
strings: [
{
id: "strings-1",
question:
"What is the time complexity of checking if two strings are equal?",
options: ["O(1)", "O(n)", "O(log n)", "O(n^2)"],
correct: 1,
explanation:
"String comparison requires checking each character, making it O(n) where n is string length.",
},
{
id: "strings-2",
question: "Which algorithm is used for pattern matching in strings?",
options: [
"Dijkstra",
"KMP (Knuth-Morris-Pratt)",
"Floyd-Warshall",
"Kruskal",
],
correct: 1,
explanation:
"KMP algorithm efficiently finds occurrences of a pattern in text in O(n+m) time.",
},
{
id: "strings-3",
question:
"What data structure is ideal for checking balanced parentheses?",
options: ["Queue", "Stack", "Heap", "Hash Set"],
correct: 1,
explanation:
"Stack's LIFO property perfectly matches parentheses matching: push opening, pop when closing matches.",
},
{
id: "strings-4",
question:
"What is the space complexity of generating all substrings of a string of length n?",
options: ["O(1)", "O(n)", "O(n^2)", "O(2^n)"],
correct: 2,
explanation:
"A string of length n has n(n+1)/2 substrings, which is O(n^2) space.",
},
{
id: "strings-5",
question:
"Which technique is used to find the longest substring without repeating characters?",
options: [
"Dynamic Programming",
"Sliding Window",
"Binary Search",
"Recursion",
],
correct: 1,
explanation:
"Sliding window with a hash set tracks unique characters and expands/contracts as needed.",
},
{
id: "strings-6",
question: "What does 'palindrome' mean for a string?",
options: [
"All characters unique",
"Reads same forwards and backwards",
"Contains only vowels",
"All characters uppercase",
],
correct: 1,
explanation:
"A palindrome reads the same forwards and backwards (e.g., 'madam', 'racecar').",
},
{
id: "strings-7",
question:
"Which operation on strings typically takes O(n) time in JavaScript?",
options: [
"Char access by index",
"Concatenation",
"Slicing",
"Finding substring",
],
correct: 3,
explanation:
"Finding a substring (indexOf, includes) requires scanning, which is O(n).",
},
{
id: "strings-8",
question: "What is 'anagram' detection about?",
options: [
"Checking palindrome",
"Checking if two strings have same characters in any order",
"Finding longest substring",
"Reversing string",
],
correct: 1,
explanation:
"Anagrams have the same characters with same frequencies but in different orders.",
},
{
id: "strings-9",
question:
"Which character encoding is commonly used in modern JavaScript strings?",
options: ["ASCII only", "UTF-16", "UTF-8", "Unicode (UTF-16 variations)"],
correct: 3,
explanation:
"JavaScript uses UCS-2/UTF-16 encoding where strings are sequences of 16-bit code units.",
},
{
id: "strings-10",
question:
"What is the best approach to check if a string is a valid number (like parseInt validation)?",
options: [
"Regular Expressions",
"Try-catch with Number()",
"Manual character iteration",
"String methods only",
],
correct: 0,
explanation:
"Regular expressions can pattern-match numeric formats efficiently and cleanly.",
},
],
linkedlist: [
{
id: "linkedlist-1",
question:
"What is the primary disadvantage of a singly linked list compared to an array?",
options: [
"Memory usage",
"Random access time",
"Insertion time",
"Deletion time",
],
correct: 1,
explanation:
"Linked lists require O(n) time to access an element by index, while arrays provide O(1) access.",
},
{
id: "linkedlist-2",
question:
"What is the time complexity of inserting at the head of a singly linked list?",
options: ["O(1)", "O(n)", "O(log n)", "O(1)"],
correct: 0,
explanation:
"Insertion at head only requires updating a couple of pointers: O(1).",
},
{
id: "linkedlist-3",
question: "Which pointer(s) does a doubly linked list node contain?",
options: ["Next only", "Prev only", "Both next and prev", "Neither"],
correct: 2,
explanation:
"Doubly linked list nodes have pointers to both next and previous nodes for bidirectional traversal.",
},
{
id: "linkedlist-4",
question: "How do you detect a cycle in a linked list efficiently?",
options: [
"Hash set visited nodes",
"Floyd's Tortoise and Hare",
"Count nodes",
"Reverse the list",
],
correct: 1,
explanation:
"Floyd's cycle detection (fast and slow pointers) uses O(1) space and O(n) time.",
},
{
id: "linkedlist-5",
question:
"What is the time complexity of reversing a singly linked list?",
options: ["O(1)", "O(n)", "O(n^2)", "O(log n)"],
correct: 1,
explanation:
"Reversing a linked list requires traversing all n nodes once, making it O(n).",
},
{
id: "linkedlist-6",
question:
"Which problem asks to find the nth node from the end of a linked list?",
options: [
"Find middle node",
"Remove duplicates",
"Find nth from end",
"Reverse list",
],
correct: 2,
explanation:
'"Nth node from the end" is a classic problem solved using two pointers with a gap of n.',
},
{
id: "linkedlist-7",
question: "In a circular linked list, the last node points to:",
options: ["null", "First node", "Middle node", "Any random node"],
correct: 1,
explanation:
"Circular linked list's last node connects back to the first (head), forming a loop.",
},
{
id: "linkedlist-8",
question:
"What is the space complexity of merging two sorted linked lists?",
options: ["O(1)", "O(n+m)", "O(log n)", "O(n)"],
correct: 0,
explanation:
"Merging sorted linked lists can be done by rearranging pointers, using O(1) extra space.",
},
{
id: "linkedlist-9",
question:
"Which technique is used to find the intersection point of two linked lists?",
options: [
"Hash set",
"Two pointers with length difference",
"Recursion",
"Stack",
],
correct: 1,
explanation:
"Find lengths, advance longer list by difference, then move both pointers together until they meet.",
},
{
id: "linkedlist-10",
question:
"What is a sentinel/dummy node used for in linked list problems?",
options: [
"Store extra data",
"Simplify edge cases",
"Increase speed",
"Reduce memory",
],
correct: 1,
explanation:
"Dummy nodes avoid handling head/ tail edge cases separately, making code cleaner.",
},
],
trees: [
{
id: "trees-1",
question:
"What is the maximum number of children a binary tree node can have?",
options: ["1", "2", "3", "Unlimited"],
correct: 1,
explanation:
"Binary tree nodes have at most two children: left and right.",
},
{
id: "trees-2",
question: "What is the time complexity of searching in a balanced BST?",
options: ["O(1)", "O(n)", "O(log n)", "O(n log n)"],
correct: 2,
explanation:
"Balanced BSTs maintain O(log n) height, enabling logarithmic-time search.",
},
{
id: "trees-3",
question:
"Which traversal visits nodes in the order: Left → Root → Right?",
options: ["Pre-order", "In-order", "Post-order", "Level-order"],
correct: 1,
explanation:
"In-order traversal processes left subtree, then root, then right subtree.",
},
{
id: "trees-4",
question: "What property must a Binary Search Tree (BST) satisfy?",
options: [
"All left descendants ≤ node < all right descendants",
"All levels fully filled",
"No cycles",
"All nodes have two children",
],
correct: 0,
explanation:
"BST invariant: left subtree values ≤ node value < right subtree values.",
},
{
id: "trees-5",
question: "How do you find the height of a binary tree?",
options: [
"Count nodes",
"Max depth from root to leaf",
"Count leaf nodes",
"Balance factor",
],
correct: 1,
explanation:
"Tree height is the number of edges on the longest path from root to leaf.",
},
{
id: "trees-6",
question: "What is the Lowest Common Ancestor (LCA) of two nodes?",
options: [
"Deepest node common to both root paths",
"Smallest value node",
"First common parent",
"Root node",
],
correct: 0,
explanation: "LCA is the deepest node that is an ancestor of both nodes.",
},
{
id: "trees-7",
question: "Which tree traversal uses a queue?",
options: ["DFS", "BFS (Level-order)", "In-order", "Pre-order"],
correct: 1,
explanation:
"Breadth-First Search (Level-order) uses a queue to process nodes level by level.",
},
{
id: "trees-8",
question: "What is a complete binary tree?",
options: [
"All levels fully filled except possibly last, left-aligned",
"All nodes have two children",
"Perfectly balanced",
"Sorted values",
],
correct: 0,
explanation:
"Complete binary tree has all levels filled except last, and nodes are as far left as possible.",
},
{
id: "trees-9",
question: "Which tree is used to implement a priority queue efficiently?",
options: ["Binary Tree", "BST", "Heap", "Trie"],
correct: 2,
explanation:
"Heaps (typically binary heaps) provide O(log n) insert and extract-max/min operations.",
},
{
id: "trees-10",
question: "What does it mean for a tree to be 'balanced'?",
options: [
"All leaf nodes at same level",
"Height difference of subtrees ≤ 1 for every node",
"No cycles",
"All nodes have 0 or 2 children",
],
correct: 1,
explanation:
"Balanced tree means for each node, heights of left/right subtrees differ by at most 1 (e.g., AVL tree).",
},
],
graphs: [
{
id: "graphs-1",
question: "What are the two main ways to represent a graph?",
options: [
"Matrix and Vector",
"Adjacency List and Adjacency Matrix",
"Edge list and Tree",
"DFS and BFS",
],
correct: 1,
explanation:
"Adjacency list (space-efficient) and adjacency matrix (O(1) edge lookup) are standard representations.",
},
{
id: "graphs-2",
question: "Which algorithm finds shortest path on unweighted graphs?",
options: ["DFS", "BFS", "Dijkstra", "Bellman-Ford"],
correct: 1,
explanation:
"BFS explores nodes level by level, naturally finding shortest path in unweighted graphs.",
},
{
id: "graphs-3",
question: "What is a directed graph?",
options: [
"Edges have no direction",
"Edges have direction",
"Edges are weighted",
"Edges are undirected",
],
correct: 1,
explanation:
"Directed graphs (digraphs) have edges with direction, indicating one-way relationships.",
},
{
id: "graphs-4",
question: "What is a cycle in a graph?",
options: [
"Path from node to itself",
"Tree structure",
"Path visiting all nodes",
"Disconnected component",
],
correct: 0,
explanation:
"A cycle is a path that starts and ends at the same vertex without repeating edges.",
},
{
id: "graphs-5",
question: "Which algorithm detects cycles in a directed graph?",
options: ["BFS", "DFS with recursion stack", "Dijkstra", "Kruskal"],
correct: 1,
explanation:
"DFS tracks recursion stack to detect back edges, indicating cycles in directed graphs.",
},
{
id: "graphs-6",
question: "What is topological sort used for?",
options: [
"Shortest path",
"Task scheduling with dependencies",
"Cycle detection",
"Finding connected components",
],
correct: 1,
explanation:
"Topological sort orders tasks so each comes before its dependencies (e.g., course prerequisites).",
},
{
id: "graphs-7",
question: "Which data structure does Dijkstra's algorithm use?",
options: ["Stack", "Queue", "Priority Queue / Min-Heap", "Hash Set"],
correct: 2,
explanation:
"Dijkstra uses a min-heap to always expand the node with smallest tentative distance.",
},
{
id: "graphs-8",
question: "What is a 'connected component' in an undirected graph?",
options: [
"Single node",
"Maximal set where every pair connected by path",
"Complete subgraph",
"Tree structure",
],
correct: 1,
explanation:
"Connected component is a maximal set of nodes where each node is reachable from every other.",
},
{
id: "graphs-9",
question: "Which algorithm finds the Minimum Spanning Tree (MST)?",
options: [
"Dijkstra",
"Prim's or Kruskal's",
"Bellman-Ford",
"Floyd-Warshall",
],
correct: 1,
explanation:
"Prim's and Kruskal's algorithms both find MST — a tree connecting all nodes with minimum total edge weight.",
},
{
id: "graphs-10",
question:
"What is the time complexity of BFS on a graph with V vertices and E edges using adjacency list?",
options: ["O(V)", "O(E)", "O(V + E)", "O(V * E)"],
correct: 2,
explanation:
"BFS visits every vertex once and explores every edge once: O(V + E).",
},
],
dp: [
{
id: "dp-1",
question:
"What are the two key properties needed for Dynamic Programming?",
options: [
"Greedy and Divide & Conquer",
"Optimal substructure and overlapping subproblems",
"Recursion and memoization",
"Iteration and base cases",
],
correct: 1,
explanation:
"DP requires optimal substructure (solution contains optimal subsolutions) and overlapping subproblems.",
},
{
id: "dp-2",
question: "What is memoization in DP?",
options: [
"Bottom-up tabulation",
"Top-down caching of results",
"Greedy choice",
"Iterative approach",
],
correct: 1,
explanation:
"Memoization stores results of expensive function calls to avoid recomputation (top-down DP).",
},
{
id: "dp-3",
question: "What is tabulation in DP?",
options: [
"Top-down recursive memoization",
"Bottom-up iterative table filling",
"Greedy approach",
"Divide and conquer",
],
correct: 1,
explanation:
"Tabulation builds DP table iteratively from base cases upward (bottom-up).",
},
{
id: "dp-4",
question:
"The Fibonacci sequence can be computed using DP in what time complexity?",
options: ["O(2^n) naive recursion", "O(n) DP", "O(log n)", "O(1)"],
correct: 1,
explanation:
"DP Fibonacci computes in O(n) by storing previous two values, vs O(2^n) naive recursion.",
},
{
id: "dp-5",
question:
"Which classic DP problem asks: given n stairs, how many ways to reach top taking 1 or 2 steps?",
options: [
"Coin Change",
"Climbing Stairs",
"House Robber",
"Longest Increasing Subsequence",
],
correct: 1,
explanation:
"Climbing Stairs is essentially Fibonacci: ways[n] = ways[n-1] + ways[n-2].",
},
{
id: "dp-6",
question: "What is the 'state' in DP?",
options: [
"Random number",
"Set of variables defining subproblem",
"Final answer",
"Recursion depth",
],
correct: 1,
explanation:
"DP state captures parameters that uniquely define a subproblem (e.g., index, remaining capacity).",
},
{
id: "dp-7",
question:
"Which DP problem involves maximizing sum of non-adjacent houses?",
options: [
"Knapsack",
"House Robber",
"Longest Common Subsequence",
"Edit Distance",
],
correct: 1,
explanation:
"House Robber: cannot rob adjacent houses; dp[i] = max(dp[i-1], dp[i-2] + nums[i]).",
},
{
id: "dp-8",
question: "What is the time complexity of the classic 0/1 Knapsack DP?",
options: ["O(n)", "O(nW) where W=capacity", "O(2^n)", "O(n^2)"],
correct: 1,
explanation:
"0/1 Knapsack DP uses a 2D table of size n x W, giving O(nW) time and space.",
},
{
id: "dp-9",
question:
"Which DP technique finds the longest increasing subsequence in O(n log n)?",
options: [
"Memoization",
"Patience sorting with binary search",
"Tabulation",
"Recursion",
],
correct: 1,
explanation:
"LIS can be optimized using patience sorting approach: maintain tails array, binary search for each element.",
},
{
id: "dp-10",
question: "What is Edit Distance (Levenshtein distance) about?",
options: [
"Sorting strings",
"Minimum operations to convert one string to another",
"Longest common substring",
"String compression",
],
correct: 1,
explanation:
"Edit distance computes minimum insertions, deletions, substitutions to transform string A into B.",
},
],
};
// ===== DATA OBJECTS =====
const dsaTopics = [
{
id: 1,
name: "Arrays",
icon: "📊",
description:
"Learn array operations, manipulations, and common interview problems",
difficulty: "Easy-Medium",
theory:
"Arrays are contiguous memory locations that store elements of the same type. They provide O(1) access time but fixed size.",
problems: [
"Two Sum",
"Maximum Subarray",
"Merge Intervals",
"Product Except Self",
"Spiral Matrix",
],
},
{
id: 2,
name: "Strings",
icon: "🔤",
description:
"Master string algorithms, pattern matching, and string manipulation",
difficulty: "Easy-Medium",
theory:
"Strings are arrays of characters. Key operations include concatenation, substring search, and pattern matching using algorithms like KMP.",
problems: [
"Longest Substring Without Repeating",
"Valid Parentheses",
"Palindrome Partitioning",
"String to Integer",
"Group Anagrams",
],
},
{
id: 3,
name: "Linked List",
icon: "🔗",
description:
"Singly, doubly, and circular linked lists with traversal techniques",
difficulty: "Medium",
theory:
"Linked lists are linear data structures where elements are linked using pointers. Allows dynamic size and efficient insertions/deletions.",
problems: [
"Reverse Linked List",
"Detect Cycle",
"Merge Two Sorted Lists",
"Remove Nth From End",
"Intersection of Two Lists",
],
},
{
id: 4,
name: "Trees",
icon: "🌳",
description:
"Binary trees, BST, traversal algorithms, and tree-based problems",
difficulty: "Medium-Hard",
theory:
"Trees are hierarchical structures. Binary trees have at most two children per node. BST maintains sorted order: left < root < right.",
problems: [
"Maximum Depth",
"Validate BST",
"Lowest Common Ancestor",
"Serialize/Deserialize",
"Path Sum",
],
},
{
id: 5,
name: "Graphs",
icon: "🕸️",
description:
"Graph representations, traversal (BFS/DFS), shortest paths, and networks",
difficulty: "Hard",
theory:
"Graphs consist of vertices connected by edges. Representations: adjacency list/matrix. Traversals: BFS (level-order) and DFS (depth-first).",
problems: [
"Clone Graph",
"Number of Islands",
"Course Schedule",
"Word Ladder",
"Network Delay Time",
],
},
{
id: 6,
name: "Dynamic Programming",
icon: "🎯",
description:
"Recursion, memoization, tabulation, and optimization problems",
difficulty: "Hard",
theory:
"DP breaks problems into overlapping subproblems. Stores solutions to avoid recomputation. Approaches: top-down (memoization) and bottom-up (tabulation).",
problems: [
"Climbing Stairs",
"Coin Change",
"Longest Increasing Subsequence",
"Edit Distance",
"House Robber",
],
},
];
const practiceProblems = [
{
id: 1,
title: "Two Sum",
difficulty: "easy",
tags: ["Arrays", "Hash Table"],
acceptance: "48.2%",
category: "arrays",
description: "Given an array of integers nums and an integer target, return indices of the two numbers that add up to target. You may assume exactly one solution exists, and you may not use the same element twice. Return the answer in any order.",
constraints: ["2 ≤ nums.length ≤ 10⁴", "-10⁹ ≤ nums[i] ≤ 10⁹", "Only one valid answer exists"],
followUp: "Can you solve it in O(n) time complexity?",
},
{
id: 2,
title: "Valid Parentheses",
difficulty: "easy",
tags: ["Strings", "Stack"],
acceptance: "40.2%",
category: "strings",
description: "Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. A string is valid if every open bracket is closed by the same type of bracket in the correct order.",
constraints: ["1 ≤ s.length ≤ 10⁴", "s consists of parentheses only '()[]{}'"],
followUp: "Can you solve it in O(n) time and O(n) space?",
},
{
id: 3,
title: "Merge Two Sorted Lists",
difficulty: "easy",
tags: ["Linked List", "Recursion"],
acceptance: "58.5%",
category: "linkedlist",
},
{
id: 4,
title: "Maximum Subarray",
difficulty: "medium",
tags: ["Arrays", "Divide & Conquer"],
acceptance: "46.2%",
category: "arrays",
},
{
id: 5,
title: "LRU Cache",
difficulty: "medium",
tags: ["Design", "Hash Table"],
acceptance: "37.5%",
category: "arrays",
},
{
id: 6,
title: "Clone Graph",
difficulty: "medium",
tags: ["Graphs", "DFS", "BFS"],
acceptance: "43.2%",
category: "graphs",
},
{
id: 7,
title: "Longest Increasing Subsequence",
difficulty: "hard",
tags: ["DP", "Binary Search"],
acceptance: "42.1%",
category: "dp",
},
{
id: 8,
title: "Word Ladder",
difficulty: "hard",
tags: ["Graphs", "BFS"],
acceptance: "31.4%",
category: "graphs",
},
{
id: 9,
title: "Trapping Rain Water",
difficulty: "hard",
tags: ["Arrays", "Two Pointers"],
acceptance: "48.7%",
category: "arrays",
},
{
id: 10,
title: "Reverse Linked List",
difficulty: "easy",
tags: ["Linked List"],
acceptance: "72.1%",
category: "linkedlist",
},
{
id: 11,
title: "Invert Binary Tree",
difficulty: "easy",
tags: ["Trees", "DFS"],
acceptance: "68.5%",
category: "trees",
},
{
id: 12,
title: "Validate BST",
difficulty: "medium",
tags: ["Trees", "Recursion"],
acceptance: "28.4%",
category: "trees",
},
{
id: 13,
title: "Number of Islands",
difficulty: "medium",
tags: ["Graphs", "DFS"],
acceptance: "54.8%",
category: "graphs",
},
{
id: 14,
title: "House Robber",
difficulty: "medium",
tags: ["DP", "Arrays"],
acceptance: "42.3%",
category: "dp",
},
{
id: 15,
title: "Course Schedule",
difficulty: "medium",
tags: ["Graphs", "Topological Sort"],
acceptance: "44.7%",
category: "graphs",
},
];
const chatbotResponses = {
"time complexity":
"Time complexity measures how an algorithm's runtime grows with input size. Common complexities: O(1) constant, O(log n) logarithmic, O(n) linear, O(n log n) linearithmic, O(n²) quadratic, O(2^n) exponential.",
"space complexity":
"Space complexity measures memory usage relative to input size. Aim for O(1) or O(n) space. In-place algorithms modify input directly.",
arrays:
"Arrays provide O(1) random access but fixed size. Use when you need fast lookups and index-based access. Key operations: insert O(n), delete O(n), search O(n) unsorted / O(log n) binary search on sorted arrays.",
"linked list":
"Linked lists offer O(1) insertion/deletion at any position but O(n) access time. Use when frequent insertions/deletions needed. Types: singly (one pointer), doubly (two pointers), circular (last points to first).",
tree: "Trees are hierarchical. Binary trees: each node has ≤2 children. BST: left < root < right. Balanced (AVL, Red-Black) ensure O(log n) operations. Traversals: inorder (left-root-right), preorder (root-left-right), postorder (left-right-root).",
graph:
"Graphs represent networks. Directed vs undirected, weighted vs unweighted, cyclic vs acyclic. Representations: adjacency list (space-efficient) vs adjacency matrix (O(1) edge lookup). Traversals: BFS (shortest path on unweighted graphs), DFS (cycle detection, topological sort).",
"dynamic programming":
"DP solves problems with optimal substructure & overlapping subproblems. Memoization (top-down) caches recursive calls. Tabulation (bottom-up) fills DP table iteratively. Steps: identify state, recurrence, base cases. Classic problems: Fibonacci, Knapsack, LCS, LIS, Coin Change.",
greedy:
"Greedy algorithms make locally optimal choices hoping for global optimum. Works when greedy choice property holds. Examples: Dijkstra's shortest path, Huffman coding, activity selection.",
sorting:
"Common sorting algorithms: Bubble O(n²), Selection O(n²), Insertion O(n²) (good for small/nearly sorted), Merge O(n log n) stable, Quick O(n log n) average, Heap O(n log n) in-place, Counting O(n+k) for bounded range, Radix O(d(n+b)).",
"binary search":
"Binary search on sorted arrays: repeatedly divide search interval in half. Time O(log n). Template: low=0, high=n-1; while low≤high: mid=(low+high)/2; if target=arr[mid] return; else adjust bounds.",
recursion:
"Recursion solves problems by breaking into smaller subproblems. Base case stops recursion. Recursive case calls function with smaller input. Use for tree traversals, backtracking, divide & conquer. Watch stack overflow for deep recursion.",
"big o":
"Big O describes upper bound of growth rate. Best, average, worst cases differ. Common: O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2^n) < O(n!). Space complexity also matters.",
bfs: "Breadth-First Search explores all neighbors before moving deeper. Use queue. Applications: shortest path (unweighted), level-order traversal, web crawling, social networks (degrees of separation).",
dfs: "Depth-First Search goes deep before backtracking. Use stack (explicit or recursion). Applications: cycle detection, topological sort, connected components, maze solving. Three tree traversals: inorder, preorder, postorder.",
"system design":
"System design involves scaling systems. Key concepts: load balancers, caching (Redis), databases (SQL vs NoSQL), CDNs, message queues, microservices, replication, sharding, CAP theorem, consistency models. Start with requirements, then high-level design, deep dive on components.",
"object oriented design":
"OOD principles: encapsulation (data hiding), inheritance (code reuse), polymorphism (same interface, different implementations), abstraction (simplify complexity). Design patterns: Singleton, Factory, Observer, Strategy, Decorator, Adapter.",
api: "API (Application Programming Interface) defines how software components interact. RESTful APIs use HTTP verbs (GET, POST, PUT, DELETE), stateless, resource-based. GraphQL allows flexible queries. Design for scalability, versioning, authentication, rate limiting.",
sql: "SQL (Structured Query Language) manages relational databases. Key commands: SELECT (retrieve), INSERT (add), UPDATE (modify), DELETE (remove), JOIN (combine tables), GROUP BY (aggregate), WHERE (filter), ORDER BY (sort). Indexes speed up reads.",
cache:
"Cache stores frequently accessed data in faster storage (memory). Strategies: LRU (least recently used), LFU (least frequently used). Cache aside, write-through, write-back patterns. Cache invalidation is critical. Redis, Memcached implementations.",
default:
"I can help with DSA topics, coding problems, system design, interview tips, and career advice. Try asking about specific algorithms, data structures, time complexity, or problem-solving strategies!",
};
// ===== STATE MANAGEMENT =====
let userProgress = {
name: "Learner",
avatar: "🚀",
completedProblems: [],
favoriteProblems: [],//here i have added a new property to store the user's favorite problems
recentProblems: [], //here i have added a new property to store the user's recent problems
favoriteProblems: [], //here i have added a new property to store the user's favorite problems
problemNotes: {},
xp: 0,
level: 1,
streak: 0,
badges: [],
lastActive: null,
quizScores: {}, // topic -> { bestScore, attempts, totalXP }
};
applySavedTheme();
// ===== INITIALIZATION =====
document.addEventListener("DOMContentLoaded", () => {
console.log("DOMContentLoaded fired, initializing app...");
loadUserData();
initLoadingScreen();
initNavbar();
initHeroSection();