-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.js
More file actions
2230 lines (2170 loc) · 114 KB
/
data.js
File metadata and controls
2230 lines (2170 loc) · 114 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
const PROBLEMS = {
beginner: [
// ── Part 1: Printing ──────────────────────────────────────────────────────
{
id: "b1",
title: "Say Hello",
description: "Print 'Hello, World!' to the screen.",
hint: "Use the print() function with the exact text inside quotes.",
expectedOutput: "Hello, World!"
},
{
id: "b2",
title: "Print a Number",
description: "Print the number 42.",
hint: "Numbers don't need quotes: print(42)",
expectedOutput: "42"
},
{
id: "b3",
title: "Two Lines",
description: "Print 'Hello' on the first line and 'World' on the second line.",
hint: "Call print() twice — once for each line.",
expectedOutput: "Hello\nWorld"
},
// ── Part 2: Variables ─────────────────────────────────────────────────────
{
id: "b4",
title: "Number Variable",
description: "Create a variable called score with the value 100 and print it.",
hint: "score = 100, then print(score)",
expectedOutput: "100"
},
{
id: "b5",
title: "String Variable",
description: "Create a variable called greeting with the value 'Hi there!' and print it.",
expectedOutput: "Hi there!"
},
{
id: "b6",
title: "Variable Math",
description: "Create variables a = 15 and b = 25, then print their sum.",
hint: "print(a + b)",
expectedOutput: "40"
},
{
id: "b7",
title: "Update a Variable",
description: "Create a variable x = 5. Then add 3 to it and print the new value.",
hint: "x = x + 3",
expectedOutput: "8"
},
// ── Part 3: Strings ───────────────────────────────────────────────────────
{
id: "b8",
title: "String Concatenation",
description: "Create two variables: first = 'Hello' and second = 'World'. Print them joined with a space between.",
hint: "Use + to join strings: first + ' ' + second",
expectedOutput: "Hello World"
},
{
id: "b9",
title: "Repeat a String",
description: "Print the word 'ha' repeated 3 times (no spaces).",
hint: "You can multiply a string: 'ha' * 3",
expectedOutput: "hahaha"
},
{
id: "b10",
title: "String Length",
description: "Print the number of characters in the word 'Python'.",
hint: "Use the len() function.",
expectedOutput: "6",
requiredKeywords: ["len("]
},
{
id: "b11",
title: "First Character",
description: "Print the first character of the string 'Python'.",
hint: "Use index 0: 'Python'[0]",
expectedOutput: "P"
},
{
id: "b12",
title: "Last Character",
description: "Print the last character of the string 'Python'.",
hint: "Use index -1: 'Python'[-1]",
expectedOutput: "n"
},
{
id: "b13",
title: "Slicing",
description: "Print the first 3 characters of the string 'Python'.",
hint: "Use slicing: 'Python'[0:3]",
expectedOutput: "Pyt"
},
// ── Part 4: String Methods ────────────────────────────────────────────────
{
id: "b14",
title: "Uppercase",
description: "Print the word 'python' in all uppercase letters.",
hint: "Strings have an .upper() method.",
expectedOutput: "PYTHON",
requiredKeywords: [".upper"]
},
{
id: "b15",
title: "Lowercase",
description: "Print the word 'HELLO' in all lowercase letters.",
hint: "Strings have a .lower() method.",
expectedOutput: "hello",
requiredKeywords: [".lower"]
},
{
id: "b16",
title: "Strip Whitespace",
description: "Print the string ' hello ' with the leading and trailing spaces removed.",
hint: "Strings have a .strip() method.",
expectedOutput: "hello",
requiredKeywords: [".strip"]
},
{
id: "b17",
title: "Replace Word",
description: "Start with the string 'Hello World'. Replace 'World' with 'Python' and print the result.",
hint: "Strings have a .replace(old, new) method.",
expectedOutput: "Hello Python",
requiredKeywords: [".replace"]
},
{
id: "b18",
title: "f-string",
description: "Create a variable age = 12. Use an f-string to print: I am 12 years old",
hint: "f\"I am {age} years old\"",
expectedOutput: "I am 12 years old",
requiredKeywords: ["{age}"]
},
// ── Part 5: Arithmetic ────────────────────────────────────────────────────
{
id: "b19",
title: "Addition",
description: "Print the result of adding 7 and 5.",
expectedOutput: "12"
},
{
id: "b20",
title: "Subtraction",
description: "Print the result of 20 minus 8.",
expectedOutput: "12"
},
{
id: "b21",
title: "Multiplication",
description: "Print the result of 6 multiplied by 7.",
expectedOutput: "42"
},
{
id: "b22",
title: "Division",
description: "Print the result of dividing 10 by 4.",
hint: "Use the / operator. The result will be a decimal.",
expectedOutput: "2.5"
},
{
id: "b23",
title: "Integer Division",
description: "Print the result of dividing 17 by 3 using integer (floor) division — no decimals, just the whole number part.",
hint: "Use the // operator.",
expectedOutput: "5",
requiredKeywords: ["//"]
},
{
id: "b24",
title: "Remainder",
description: "Print the remainder when 17 is divided by 5.",
hint: "Use the % (modulo) operator.",
expectedOutput: "2",
requiredKeywords: ["%"]
},
{
id: "b25",
title: "Power",
description: "Print 2 to the power of 10.",
hint: "Use the ** operator: 2 ** 10",
expectedOutput: "1024",
requiredKeywords: ["**"]
},
{
id: "b26",
title: "Order of Operations",
description: "Print the result of (10 + 5) * 2 - 3.",
hint: "Python follows standard math order: parentheses first.",
expectedOutput: "27"
},
// ── Part 6: Built-in Math Functions ──────────────────────────────────────
{
id: "b27",
title: "Absolute Value",
description: "Print the absolute value of -42.",
hint: "Use the abs() function.",
expectedOutput: "42",
requiredKeywords: ["abs("]
},
{
id: "b28",
title: "Round a Number",
description: "Print 3.7 rounded to the nearest whole number.",
hint: "Use the round() function.",
expectedOutput: "4",
requiredKeywords: ["round("]
},
{
id: "b29",
title: "Maximum of Three",
description: "Print the largest of the numbers 3, 7, and 2.",
hint: "Use the max() function.",
expectedOutput: "7",
requiredKeywords: ["max("]
},
{
id: "b30",
title: "Minimum of Three",
description: "Print the smallest of the numbers 3, 7, and 2.",
hint: "Use the min() function.",
expectedOutput: "2",
requiredKeywords: ["min("]
},
// ── Part 7: Types & Conversion ────────────────────────────────────────────
{
id: "b31",
title: "Type of Integer",
description: "Print the type of the value 42.",
hint: "Use print(type(42))",
expectedOutput: "<class 'int'>"
},
{
id: "b32",
title: "Type of Float",
description: "Print the type of the value 3.14.",
hint: "Use print(type(3.14))",
expectedOutput: "<class 'float'>"
},
{
id: "b33",
title: "Type of String",
description: "Print the type of the value 'hello'.",
hint: "Use print(type('hello'))",
expectedOutput: "<class 'str'>"
},
{
id: "b34",
title: "String to Integer",
description: "Convert the string '25' to an integer, add 5 to it, and print the result.",
hint: "Use int() to convert: int('25')",
expectedOutput: "30",
requiredKeywords: ["int("]
},
{
id: "b35",
title: "Integer to Float",
description: "Convert the integer 5 to a float and print it.",
hint: "Use float() to convert: float(5)",
expectedOutput: "5.0",
requiredKeywords: ["float("]
},
{
id: "b36",
title: "Number to String",
description: "Convert the number 42 to a string, join it with '!' and print the result.",
hint: "Use str() to convert: str(42) + '!'",
expectedOutput: "42!",
requiredKeywords: ["str("]
},
// ── Part 8: Lists Introduction ────────────────────────────────────────────
{
id: "b37",
title: "Create a List",
description: "Create a list called fruits containing 'apple', 'banana', and 'cherry'. Print the list.",
hint: "fruits = ['apple', 'banana', 'cherry']",
expectedOutput: "['apple', 'banana', 'cherry']"
},
{
id: "b38",
title: "List Index",
description: "Create the list nums = [10, 20, 30, 40, 50] and print the third item.",
hint: "List indexes start at 0, so the third item is index 2: nums[2]",
expectedOutput: "30"
},
{
id: "b39",
title: "Last List Item",
description: "Create the list nums = [10, 20, 30, 40, 50] and print the last item using a negative index.",
hint: "Use index -1 to get the last item: nums[-1]",
expectedOutput: "50"
},
{
id: "b40",
title: "Length of a List",
description: "Print the number of items in the list [10, 20, 30, 40, 50].",
hint: "Use len().",
expectedOutput: "5",
requiredKeywords: ["len("]
}
],
intermediate: [
// ── Loops ─────────────────────────────────────────────────────────────────
{
id: "i1",
title: "Count to Five",
description: "Print the numbers 1 to 5, each on a new line.",
hint: "Use a for loop with range().",
expectedOutput: "1\n2\n3\n4\n5"
},
{
id: "i2",
title: "Count Down",
description: "Print numbers from 5 down to 1, each on a new line.",
hint: "Use range(5, 0, -1).",
expectedOutput: "5\n4\n3\n2\n1"
},
{
id: "i3",
title: "Even Numbers",
description: "Print all even numbers from 2 to 10, each on a new line.",
hint: "Use range(2, 11, 2) or check with % 2.",
expectedOutput: "2\n4\n6\n8\n10"
},
{
id: "i4",
title: "Multiplication Table",
description: "Print the 3 times table from 3×1 to 3×10, one result per line.",
hint: "for i in range(1, 11): print(3 * i)",
expectedOutput: "3\n6\n9\n12\n15\n18\n21\n24\n27\n30"
},
{
id: "i5",
title: "Sum of 1 to 100",
description: "Print the sum of all integers from 1 to 100.",
hint: "Use sum(range(1, 101)) or a loop.",
expectedOutput: "5050"
},
{
id: "i6",
title: "While Loop",
description: "Use a while loop to print the numbers 1 to 5, each on a new line.",
hint: "Start with n = 1, loop while n <= 5.",
expectedOutput: "1\n2\n3\n4\n5",
requiredKeywords: ["while"]
},
{
id: "i7",
title: "Star Triangle",
description: "Print a triangle of stars with 5 rows: row 1 has 1 star, row 2 has 2, ..., row 5 has 5.",
hint: "for i in range(1, 6): print('*' * i)",
expectedOutput: "*\n**\n***\n****\n*****"
},
{
id: "i8",
title: "FizzBuzz",
description: "Print numbers 1 to 15. For multiples of 3 print 'Fizz', for multiples of 5 print 'Buzz', for multiples of both print 'FizzBuzz'.",
expectedOutput: "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz"
},
// ── Lists ─────────────────────────────────────────────────────────────────
{
id: "i9",
title: "List Append",
description: "Start with an empty list, append the numbers 1, 2, and 3, then print the list.",
expectedOutput: "[1, 2, 3]"
},
{
id: "i10",
title: "Sum a List",
description: "Create the list [1, 2, 3, 4, 5] and print its sum.",
hint: "Use the sum() function.",
expectedOutput: "15",
requiredKeywords: ["sum("]
},
{
id: "i11",
title: "List Maximum",
description: "Print the largest number in the list [3, 1, 4, 1, 5, 9, 2, 6].",
hint: "Use the max() function.",
expectedOutput: "9",
requiredKeywords: ["max("]
},
{
id: "i12",
title: "Reverse a List",
description: "Print the list [1, 2, 3, 4, 5] in reverse order.",
hint: "Use slicing: my_list[::-1]",
expectedOutput: "[5, 4, 3, 2, 1]"
},
{
id: "i13",
title: "List Slicing",
description: "Print the first 3 items of the list [10, 20, 30, 40, 50].",
hint: "Use slicing: my_list[:3]",
expectedOutput: "[10, 20, 30]"
},
{
id: "i14",
title: "Remove Duplicates",
description: "Given the list [1, 2, 2, 3, 3, 3, 4], print a sorted list with duplicates removed.",
hint: "Convert to a set, then back to a sorted list.",
expectedOutput: "[1, 2, 3, 4]",
requiredKeywords: ["set("]
},
{
id: "i15",
title: "List of Squares",
description: "Use a list comprehension to create a list of squares of 1 to 5 and print it.",
hint: "[x**2 for x in range(1, 6)]",
expectedOutput: "[1, 4, 9, 16, 25]"
},
// ── Functions ─────────────────────────────────────────────────────────────
{
id: "i16",
title: "Double a Number",
description: "Write a function called double that returns a number multiplied by 2. Print double(6).",
hint: "def double(n): return n * 2",
expectedOutput: "12",
requiredKeywords: ["def "]
},
{
id: "i17",
title: "Factorial",
description: "Write a function called factorial that returns n! (n factorial). Print factorial(5).",
hint: "Use a loop: result = 1, multiply by each number up to n.",
expectedOutput: "120",
requiredKeywords: ["def "]
},
{
id: "i18",
title: "Is Even",
description: "Write a function called is_even that returns True if a number is even, False otherwise. Print is_even(4) then is_even(7), each on a new line.",
hint: "Use the % operator: n % 2 == 0",
expectedOutput: "True\nFalse",
requiredKeywords: ["def "]
},
{
id: "i19",
title: "Default Argument",
description: "Write a function greet(name='World') that prints 'Hello, ' followed by the name and '!'. Call greet('Alice').",
hint: "def greet(name='World'): print(f'Hello, {name}!')",
expectedOutput: "Hello, Alice!",
requiredKeywords: ["def "]
},
{
id: "i20",
title: "Sum of Digits",
description: "Write a function sum_digits(n) that returns the sum of digits of n. Print sum_digits(123).",
hint: "Convert to string, then sum each digit as int.",
expectedOutput: "6",
requiredKeywords: ["def "]
},
// ── Conditionals ──────────────────────────────────────────────────────────
{
id: "i21",
title: "Positive Check",
description: "Print 'positive' if the number 8 is greater than 0, otherwise print 'not positive'.",
expectedOutput: "positive"
},
{
id: "i22",
title: "Grade",
description: "Given score = 75, print 'A' if score >= 90, 'B' if >= 80, 'C' if >= 70, otherwise 'F'.",
expectedOutput: "C"
},
{
id: "i23",
title: "Is Palindrome",
description: "Check if the string 'racecar' reads the same forwards and backwards. Print True or False.",
hint: "Compare the string to its reverse: s == s[::-1]",
expectedOutput: "True"
},
// ── Strings ───────────────────────────────────────────────────────────────
{
id: "i24",
title: "Count Vowels",
description: "Count and print the number of vowels (a, e, i, o, u) in the string 'hello world'.",
hint: "Loop through each character and check if it's in 'aeiou'.",
expectedOutput: "3"
},
{
id: "i25",
title: "Join Words",
description: "Join the list ['Hello', 'World', 'from', 'Python'] into a single string with spaces between words and print it.",
hint: "Use ' '.join(my_list)",
expectedOutput: "Hello World from Python",
requiredKeywords: [".join("]
},
{
id: "i26",
title: "Word Count",
description: "Print the number of words in the sentence 'the quick brown fox jumps over the lazy dog'.",
hint: "Use .split() and len().",
expectedOutput: "9",
requiredKeywords: [".split(", "len("]
},
// ── Algorithms ────────────────────────────────────────────────────────────
{
id: "i27",
title: "Fibonacci Sequence",
description: "Print the first 8 Fibonacci numbers, each on a new line. Start with 0 and 1.",
hint: "a, b = 0, 1. Each step: a, b = b, a + b.",
expectedOutput: "0\n1\n1\n2\n3\n5\n8\n13"
},
{
id: "i28",
title: "Count Divisible",
description: "Print how many numbers from 1 to 50 are divisible by 7.",
hint: "Use a loop and check n % 7 == 0.",
expectedOutput: "7"
},
{
id: "i29",
title: "Sort a List",
description: "Print the list [3, 1, 4, 1, 5, 9, 2, 6] sorted in ascending order.",
hint: "Use sorted().",
expectedOutput: "[1, 1, 2, 3, 4, 5, 6, 9]",
requiredKeywords: ["sorted("]
},
{
id: "i30",
title: "Nested Loop — Times Table",
description: "Print the multiplication table for 2 and 3. Each line: '2 x 1 = 2', '2 x 2 = 4', ..., '3 x 5 = 15' (2×1 through 2×5, then 3×1 through 3×5).",
hint: "Use a nested for loop: for n in [2,3]: for i in range(1,6):",
expectedOutput: "2 x 1 = 2\n2 x 2 = 4\n2 x 3 = 6\n2 x 4 = 8\n2 x 5 = 10\n3 x 1 = 3\n3 x 2 = 6\n3 x 3 = 9\n3 x 4 = 12\n3 x 5 = 15"
}
],
advanced: [
{
id: "a1",
title: "Dictionary Lookup",
description: "Create a dictionary with keys 'name' and 'age' set to 'Bob' and 12. Print the value of 'name'.",
expectedOutput: "Bob"
},
{
id: "a2",
title: "List Comprehension",
description: "Use a list comprehension to create a list of squares of numbers 1 to 5 and print it.",
hint: "[x**2 for x in ...]",
expectedOutput: "[1, 4, 9, 16, 25]"
},
{
id: "a3",
title: "Simple Class",
description: "Create a class called Dog with a method speak() that returns 'Woof!'. Create an instance and print dog.speak().",
expectedOutput: "Woof!",
requiredKeywords: ["class "]
},
{
id: "a4",
title: "Handle an Error",
description: "Use try/except to attempt int('abc') and print 'error caught' if it fails.",
expectedOutput: "error caught",
requiredKeywords: ["try"]
},
{
id: "a5",
title: "Filter a List",
description: "From the list [1,2,3,4,5,6], print a new list containing only numbers greater than 3.",
hint: "Use a list comprehension with a condition.",
expectedOutput: "[4, 5, 6]"
},
{
id: "a6",
title: "Count Words",
description: "Print the number of words in the string 'the quick brown fox'.",
hint: "Use the .split() method and len().",
expectedOutput: "4",
requiredKeywords: [".split(", "len("]
},
{
id: "a7",
title: "Reverse a String",
description: "Print the string 'Python' reversed.",
hint: "Use slicing: string[::-1]",
expectedOutput: "nohtyP"
},
{
id: "a8",
title: "Dictionary Keys",
description: "Create a dictionary {'a': 1, 'b': 2, 'c': 3} and print a sorted list of its keys.",
expectedOutput: "['a', 'b', 'c']",
requiredKeywords: ["sorted("]
}
]
};
const TUTORIAL = [
{
id: "t1",
title: "Your First Line of Code",
explanation: {
what: "print() is a built-in function that displays output on the screen. Anything you put inside the parentheses gets shown.",
when: "Any time you want to see a result, show a message, or check what a value is.",
example: `print("Hello, Python!")\nprint(42)`
},
questions: [
{ id: "t1_1", description: "Print Hello, Python! to the screen.", expectedOutput: "Hello, Python!" },
{ id: "t1_2", description: "Print the number 42.", expectedOutput: "42" },
{ id: "t1_3", description: "Print Hello on the first line and World on the second line.", expectedOutput: "Hello\nWorld" }
]
},
{
id: "t2",
title: "Numbers and Math",
explanation: {
what: "Python can do arithmetic using + (add), - (subtract), * (multiply), and / (divide). Python follows standard math order: parentheses first, then * and /, then + and -.",
when: "Any time you need to calculate something — scores, distances, prices, ages.",
example: `print(10 + 5) # 15\nprint(3 * 4) # 12\nprint(10 / 4) # 2.5\nprint(3 * 4 + 2) # 14`
},
questions: [
{ id: "t2_1", description: "Print the result of 3 * 4 + 2.", expectedOutput: "14" },
{ id: "t2_2", description: "Print the result of 10 - 3.", expectedOutput: "7" },
{ id: "t2_3", description: "Print the result of 15 / 2.", expectedOutput: "7.5" }
]
},
{
id: "t3",
title: "Variables",
explanation: {
what: "A variable is a named container that stores a value. You create one with: name = value.\n\nNaming rules:\n• Use only letters, digits, and underscores\n• Cannot start with a digit (2fast is invalid)\n• No spaces or special characters\n• Case-sensitive: name and Name are different variables\n• Cannot use reserved words: if, for, while, True, False, and, or, not, in, return",
when: "Any time you want to save a value and use it again later — like storing a player name, a score, or a calculation result.",
example: `name = "Alex"\nscore = 100\nprint(name) # Alex\nprint(score) # 100\n\n# Case matters!\nmy_score = 50\nMyScore = 99\nprint(my_score) # 50`
},
questions: [
{ id: "t3_1", description: "Create a variable called name with the value \"Alex\" and print it.", expectedOutput: "Alex" },
{ id: "t3_2", description: "Create my_score = 100 and MyScore = 200. Print my_score.", expectedOutput: "100" },
{ id: "t3_3", description: "Create x = 5 and y = 3, then print their sum.", expectedOutput: "8" }
]
},
{
id: "t4",
title: "Data Types",
explanation: {
what: "Every value in Python has a type. The four basic types are:\n• int — whole numbers like 42\n• float — decimal numbers like 3.14\n• str — text in quotes like \"hello\"\n• bool — True or False\n\nUse type() to check what type something is.",
when: "When you need to know what kind of value you are working with — especially before doing math or joining values together.",
example: `print(type(42)) # <class 'int'>\nprint(type(3.14)) # <class 'float'>\nprint(type("hello")) # <class 'str'>\nprint(type(True)) # <class 'bool'>`
},
questions: [
{ id: "t4_1", description: "Print the type of 42.", expectedOutput: "<class 'int'>" },
{ id: "t4_2", description: "Print the type of 3.14.", expectedOutput: "<class 'float'>" },
{ id: "t4_3", description: "Print the type of \"hello\".", expectedOutput: "<class 'str'>" }
]
},
{
id: "t5",
title: "Type Conversion",
explanation: {
what: "You can convert a value from one type to another:\n• int() converts to a whole number\n• float() converts to a decimal\n• str() converts to text",
when: "When you have text that contains a number and need to do math with it, or when you need to join a number with a string.",
example: `num = int("5") # "5" becomes 5\ndec = float(3) # 3 becomes 3.0\ntxt = str(42) # 42 becomes "42"\nprint(num + 10) # 15\nprint(txt + "!") # 42!`
},
questions: [
{ id: "t5_1", description: "Convert the string \"7\" to an integer, add 3, and print the result.", expectedOutput: "10" },
{ id: "t5_2", description: "Convert the integer 5 to a float and print it.", expectedOutput: "5.0" },
{ id: "t5_3", description: "Convert the number 42 to a string, join it with \"!\", and print the result.", expectedOutput: "42!" }
]
},
{
id: "t6",
title: "Text (Strings)",
explanation: {
what: "A string is text wrapped in quotes (single or double — both work). You can:\n• Join two strings with + (concatenation)\n• Repeat a string with * and a number\n• Get its length with len()",
when: "Any time you work with words, names, sentences, or messages.",
example: `greeting = "Hello" + " " + "World"\nprint(greeting) # Hello World\nprint("ha" * 3) # hahaha\nprint(len("Python")) # 6`
},
questions: [
{ id: "t6_1", description: "Create first = \"Hello\" and second = \"World\". Print them joined with a space between.", expectedOutput: "Hello World" },
{ id: "t6_2", description: "Print the word \"ha\" repeated 3 times (no spaces).", expectedOutput: "hahaha" },
{ id: "t6_3", description: "Print the number of characters in the word \"Python\".", expectedOutput: "6" }
]
},
{
id: "t7",
title: "True and False",
explanation: {
what: "A bool is a value that is either True or False. Comparison operators produce bools:\n• == equal to\n• != not equal to\n• > greater than\n• < less than\n• >= greater than or equal\n• <= less than or equal",
when: "Any time you need to check a condition — is the score high enough? Are two values equal? Is a number positive?",
example: `print(10 > 3) # True\nprint(5 == 5) # True\nprint(4 != 4) # False\nprint(7 >= 7) # True`
},
questions: [
{ id: "t7_1", description: "Print whether 10 > 3.", expectedOutput: "True" },
{ id: "t7_2", description: "Print whether 5 == 5.", expectedOutput: "True" },
{ id: "t7_3", description: "Print whether 7 != 7.", expectedOutput: "False" }
]
},
{
id: "t8",
title: "And, Or, Not",
explanation: {
what: "Logical operators combine boolean values:\n• and — both conditions must be True\n• or — at least one must be True\n• not — flips True to False and False to True",
when: "When a decision depends on more than one condition — like checking that someone is both old enough and has a ticket.",
example: `age = 9\nprint(age > 5 and age < 13) # True\nprint(age > 10 or age < 5) # False\nprint(not True) # False\nprint(not False) # True`
},
questions: [
{ id: "t8_1", description: "Given age = 9, print whether age > 5 and age < 13.", expectedOutput: "True" },
{ id: "t8_2", description: "Given x = 3, print whether x > 10 or x < 5.", expectedOutput: "True" },
{ id: "t8_3", description: "Given raining = False, print not raining.", expectedOutput: "True" }
]
},
{
id: "t9",
title: "Making Decisions",
explanation: {
what: "An if statement runs a block of code only when a condition is True. else runs when the condition is False. The code inside the block must be indented (4 spaces or 1 tab).",
when: "Any time your program needs to behave differently depending on a value — show different messages for different ages, handle correct and incorrect answers.",
example: `age = 10\nif age < 13:\n print("child")\nelse:\n print("teen")`
},
questions: [
{ id: "t9_1", description: "Given age = 10, print \"child\" if age is less than 13, otherwise print \"teen\".", expectedOutput: "child" },
{ id: "t9_2", description: "Given num = 5, print \"big\" if num is greater than 3, otherwise print \"small\".", expectedOutput: "big" },
{ id: "t9_3", description: "Given temperature = 35, print \"hot\" if temperature is greater than 30, otherwise print \"cool\".", expectedOutput: "hot" }
]
},
{
id: "t10",
title: "More Conditions",
explanation: {
what: "elif (short for 'else if') lets you check multiple conditions in sequence. Python checks each one in order and runs the first block that matches. If none match, else runs.",
when: "When there are more than two possible outcomes — like assigning letter grades A, B, C, or F.",
example: `score = 75\nif score >= 90:\n print("A")\nelif score >= 80:\n print("B")\nelif score >= 70:\n print("C")\nelse:\n print("F")`
},
questions: [
{ id: "t10_1", description: "Given score = 75, print \"A\" if >= 90, \"B\" if >= 80, \"C\" if >= 70, otherwise \"F\".", expectedOutput: "C" },
{ id: "t10_2", description: "Given hour = 14, print \"morning\" if hour < 12, \"afternoon\" if hour < 18, otherwise \"evening\".", expectedOutput: "afternoon" },
{ id: "t10_3", description: "Given num = 0, print \"positive\" if > 0, \"negative\" if < 0, otherwise \"zero\".", expectedOutput: "zero" }
]
},
{
id: "t11",
title: "Repeating Things",
explanation: {
what: "A for loop repeats a block of code for each value in a sequence. range(n) gives numbers from 0 up to (but not including) n. range(1, n+1) gives 1 through n.",
when: "Any time you need to do something multiple times — printing numbers, adding up a total, building a pattern.",
example: `for i in range(3):\n print(i) # prints 0, then 1, then 2 (one per line)\n\nfor i in range(1, 6):\n print(i) # prints 1, then 2, then 3, then 4, then 5`
},
questions: [
{ id: "t11_1", description: "Print the numbers 1 to 5, each on a new line.", expectedOutput: "1\n2\n3\n4\n5" },
{ id: "t11_2", description: "Print \"hello\" 3 times, each on a new line.", expectedOutput: "hello\nhello\nhello" },
{ id: "t11_3", description: "Use a loop to calculate and print the sum of numbers 1 to 5.", expectedOutput: "15" }
]
},
{
id: "t12",
title: "Controlling the Range",
explanation: {
what: "range(x, y) starts at x and stops before y. range(x, y, z) also sets the step — how much to add each time. Use a negative step to count down.",
when: "When you need to loop over a specific span — starting mid-way, stepping by twos, or counting backwards.",
example: `for i in range(3, 8): # prints 3, 4, 5, 6, 7 (one per line)\n print(i)\n\nfor i in range(0, 11, 2): # prints 0, 2, 4, 6, 8, 10 (one per line)\n print(i)\n\nfor i in range(5, 0, -1): # prints 5, 4, 3, 2, 1 (one per line)\n print(i)`
},
questions: [
{ id: "t12_1", description: "Print the numbers from 3 to 7, each on a new line.", expectedOutput: "3\n4\n5\n6\n7" },
{ id: "t12_2", description: "Print the even numbers from 2 to 10, each on a new line.", expectedOutput: "2\n4\n6\n8\n10" },
{ id: "t12_3", description: "Print the numbers counting down from 5 to 1, each on a new line.", expectedOutput: "5\n4\n3\n2\n1" }
]
},
{
id: "t13",
title: "Lists",
explanation: {
what: "A list stores multiple values in one variable, in order, inside square brackets [ ]. Items are accessed by their index (position) starting at 0. len() tells you how many items are in the list.",
when: "Any time you have multiple related values to keep together — a list of names, scores, colours, or anything.",
example: `fruits = ["apple", "banana", "cherry"]\nprint(fruits) # ['apple', 'banana', 'cherry']\nprint(fruits[0]) # apple (first item)\nprint(fruits[1]) # banana (second item)\nprint(len(fruits)) # 3`
},
questions: [
{ id: "t13_1", description: "Create a list called fruits containing \"apple\", \"banana\", and \"cherry\". Print the list.", expectedOutput: "['apple', 'banana', 'cherry']" },
{ id: "t13_2", description: "Create the list [10, 20, 30, 40, 50] and print the second item.", expectedOutput: "20" },
{ id: "t13_3", description: "Print the number of items in the list [\"red\", \"green\", \"blue\"].", expectedOutput: "3" }
]
}
];
const INTERVIEW = [
// ── DS1: Array ──────────────────────────────────────────────────────────────
{
id: "ds1",
title: "Array",
learn: {
what: "An ordered, index-based collection. Python's list is a dynamic array — it resizes automatically. Elements are stored contiguously so random access is O(1), but inserting or deleting in the middle shifts elements and costs O(n).",
operations: [
{ name: "Access by index", signature: "list[i] → item", complexity: "O(1)", description: "Direct index lookup — no traversal needed" },
{ name: "Append", signature: "list.append(x) → None", complexity: "O(1) amortized", description: "Add to end; occasionally triggers a resize but averages O(1)" },
{ name: "Insert / delete at middle", signature: "list.insert(i, x) / del list[i]", complexity: "O(n)", description: "All elements after the target index must shift" },
{ name: "Search (unsorted)", signature: "x in list → bool", complexity: "O(n)", description: "Must scan every element until a match is found" },
{ name: "Slice [i:j]", signature: "list[i:j] → list", complexity: "O(k)", description: "Copies k = j-i elements into a new list" },
],
pythonTools: ["enumerate(iterable)", "zip(a, b)", "any(iterable)", "all(iterable)"],
example: `nums = [3, 1, 4, 1, 5]
# enumerate: index + value
for i, v in enumerate(nums):
pass # i=0,v=3 i=1,v=1 ...
# zip: parallel iteration
a, b = [1, 2, 3], [4, 5, 6]
for x, y in zip(a, b):
pass # (1,4), (2,5), (3,6)
# two-pointer template
left, right = 0, len(nums) - 1
while left < right:
left += 1
right -= 1
# any / all
print(any(v > 4 for v in nums)) # True
print(all(v > 0 for v in nums)) # True`,
},
problems: [
{
id: "ds1_1", title: "Two Sum", difficulty: "easy",
leetcode: { number: 1, url: "https://leetcode.com/problems/two-sum/" },
description: "Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target. Assume exactly one solution exists. Return indices in ascending order.",
stub: "def two_sum(nums, target):\n pass",
functionName: "two_sum",
tests: [
{ args: [[2,7,11,15], 9], expected: [0,1] },
{ args: [[3,2,4], 6], expected: [1,2] },
{ args: [[3,3], 6], expected: [0,1] },
{ args: [[1,5,3,2,4], 6], expected: [3,4] },
{ args: [[0,4,3,0], 0], expected: [0,3] },
{ args: [[-1,-2,-3,-4,-5], -8], expected: [2,4] },
{ args: [[1,2,3,4,5], 9], expected: [3,4] },
{ args: [[5,75,25], 100], expected: [1,2] },
{ args: [[2,5,5,11], 10], expected: [1,2] },
{ args: [[1,3,4,2], 6], expected: [2,3] },
],
},
{
id: "ds1_2", title: "Best Time to Buy and Sell Stock", difficulty: "easy",
leetcode: { number: 121, url: "https://leetcode.com/problems/best-time-to-buy-and-sell-stock/" },
description: "Given an array prices where prices[i] is the price of a stock on day i, return the maximum profit you can achieve from one buy and one sell. If no profit is possible, return 0.",
stub: "def max_profit(prices):\n pass",
functionName: "max_profit",
tests: [
{ args: [[7,1,5,3,6,4]], expected: 5 },
{ args: [[7,6,4,3,1]], expected: 0 },
{ args: [[1,2]], expected: 1 },
{ args: [[2,4,1]], expected: 2 },
{ args: [[3,3,3,3]], expected: 0 },
{ args: [[1]], expected: 0 },
{ args: [[1,2,3,4,5]], expected: 4 },
{ args: [[5,4,3,2,1,6]], expected: 5 },
{ args: [[2,1,4]], expected: 3 },
],
},
{
id: "ds1_3", title: "Contains Duplicate", difficulty: "easy",
leetcode: { number: 217, url: "https://leetcode.com/problems/contains-duplicate/" },
description: "Given an integer array nums, return True if any value appears at least twice in the array, and False if every element is distinct.",
stub: "def contains_duplicate(nums):\n pass",
functionName: "contains_duplicate",
tests: [
{ args: [[1,2,3,1]], expected: true },
{ args: [[1,2,3,4]], expected: false },
{ args: [[1,1,1,3,3,4,3,2,4,2]], expected: true },
{ args: [[1]], expected: false },
{ args: [[-1,-1]], expected: true },
{ args: [[0,0]], expected: true },
{ args: [[1,2,3,4,5,6,7,8,9]], expected: false },
{ args: [[1000000,1000000]], expected: true },
],
},
{
id: "ds1_4", title: "Maximum Subarray", difficulty: "easy",
leetcode: { number: 53, url: "https://leetcode.com/problems/maximum-subarray/" },
description: "Given an integer array nums, find the contiguous subarray with the largest sum and return its sum. (Kadane's algorithm)",
stub: "def max_subarray(nums):\n pass",
functionName: "max_subarray",
tests: [
{ args: [[-2,1,-3,4,-1,2,1,-5,4]], expected: 6 },
{ args: [[1]], expected: 1 },
{ args: [[5,4,-1,7,8]], expected: 23 },
{ args: [[-1]], expected: -1 },
{ args: [[-2,-1]], expected: -1 },
{ args: [[0]], expected: 0 },
{ args: [[1,-2,3,-4,5]], expected: 5 },
{ args: [[2,-1,2,1,-1]], expected: 4 },
{ args: [[-3,-2,-1]], expected: -1 },
],
},
{
id: "ds1_5", title: "Product of Array Except Self", difficulty: "medium",
leetcode: { number: 238, url: "https://leetcode.com/problems/product-of-array-except-self/" },
description: "Given an integer array nums, return an array answer such that answer[i] is equal to the product of all elements of nums except nums[i]. Solve it in O(n) without using division.",
stub: "def product_except_self(nums):\n pass",
functionName: "product_except_self",
tests: [
{ args: [[1,2,3,4]], expected: [24,12,8,6] },
{ args: [[-1,1,0,-3,3]], expected: [0,0,9,0,0] },
{ args: [[2,3]], expected: [3,2] },
{ args: [[1,0,3,4]], expected: [0,12,0,0] },
{ args: [[2,4,6]], expected: [24,12,8] },
{ args: [[-1,-2,-3,-4]], expected: [-24,-12,-8,-6] },
{ args: [[5,5]], expected: [5,5] },
{ args: [[0,0]], expected: [0,0] },
{ args: [[1,1,1,1]], expected: [1,1,1,1] },
],
},
],
},
// ── DS2: Hash Map ────────────────────────────────────────────────────────────
{
id: "ds2",
title: "Hash Map",
learn: {
what: "A key-value store with O(1) average-case insert, delete, and lookup. Python's dict is a hash map. Counter counts element frequencies. defaultdict avoids KeyError by providing a default factory for missing keys.",
operations: [
{ name: "Get / set / delete", signature: "d[k] / d[k]=v / del d[k]", complexity: "O(1) average", description: "Hash function maps key to bucket; collisions make worst case O(n)" },
{ name: "Iterate all keys", signature: "for k in d → keys", complexity: "O(n)", description: "Visits every key in insertion order (Python 3.7+)" },
{ name: "Counter(iterable)", signature: "Counter(it) → Counter", complexity: "O(n)", description: "Counts each element in one pass" },
{ name: "most_common(k)", signature: "c.most_common(k) → [(k,n),...]",complexity: "O(n log k)", description: "Returns k most frequent elements using a heap internally" },
],
pythonTools: ["dict.get(key, default)", "Counter(iterable)", "defaultdict(list)"],
example: `from collections import Counter, defaultdict
# dict: frequency map
freq = {}
for c in "hello":
freq[c] = freq.get(c, 0) + 1 # {'h':1,'e':1,'l':2,'o':1}
# Counter: same thing, one line
freq = Counter("hello")
print(freq.most_common(2)) # [('l', 2), ('h', 1)]
# defaultdict: no KeyError on missing key
graph = defaultdict(list)
graph['a'].append('b') # auto-creates 'a' key
# two-sum lookup pattern
seen = {}
for i, v in enumerate([2, 7, 11]):
if 9 - v in seen:
print([seen[9 - v], i]) # [0, 1]
seen[v] = i`,
},
problems: [
{
id: "ds2_1", title: "Valid Anagram", difficulty: "easy",
leetcode: { number: 242, url: "https://leetcode.com/problems/valid-anagram/" },
description: "Given two strings s and t, return True if t is an anagram of s, and False otherwise.",
stub: "def is_anagram(s, t):\n pass",
functionName: "is_anagram",
tests: [
{ args: ["anagram", "nagaram"], expected: true },
{ args: ["rat", "car"], expected: false },
{ args: ["a", "a"], expected: true },
{ args: ["", ""], expected: true },
{ args: ["ab", "ba"], expected: true },
{ args: ["abc", "bca"], expected: true },
{ args: ["ab", "a"], expected: false },
{ args: ["aab", "baa"], expected: true },
{ args: ["aacc", "ccac"], expected: false },
],
},
{
id: "ds2_2", title: "Ransom Note", difficulty: "easy",
leetcode: { number: 383, url: "https://leetcode.com/problems/ransom-note/" },
description: "Given two strings ransomNote and magazine, return True if ransomNote can be constructed by using the letters from magazine (each letter used at most once).",
stub: "def can_construct(ransom_note, magazine):\n pass",
functionName: "can_construct",
tests: [
{ args: ["a", "b"], expected: false },
{ args: ["aa", "ab"], expected: false },
{ args: ["aa", "aab"], expected: true },
{ args: ["", ""], expected: true },
{ args: ["", "a"], expected: true },
{ args: ["a", ""], expected: false },
{ args: ["abc", "cbad"], expected: true },
{ args: ["aab", "aab"], expected: true },
{ args: ["aab", "aaa"], expected: false },
],
},
{
id: "ds2_3", title: "Word Pattern", difficulty: "easy",
leetcode: { number: 290, url: "https://leetcode.com/problems/word-pattern/" },
description: "Given a pattern and a string s, return True if s follows the same pattern. Each letter in pattern maps to exactly one word and each word maps to exactly one letter.",
stub: "def word_pattern(pattern, s):\n pass",
functionName: "word_pattern",
tests: [
{ args: ["abba", "dog cat cat dog"], expected: true },
{ args: ["abba", "dog cat cat fish"], expected: false },
{ args: ["aaaa", "dog cat cat dog"], expected: false },
{ args: ["ab", "dog dog"], expected: false },
{ args: ["a", "dog"], expected: true },
{ args: ["aa", "dog dog"], expected: true },
{ args: ["ab", "dog cat"], expected: true },
{ args: ["abba", "dog dog dog dog"], expected: false },
{ args: ["abc", "b c b"], expected: false },
],
},
{
id: "ds2_4", title: "First Unique Character in a String", difficulty: "easy",
leetcode: { number: 387, url: "https://leetcode.com/problems/first-unique-character-in-a-string/" },
description: "Given a string s, find the first non-repeating character and return its index. If it does not exist, return -1.",
stub: "def first_uniq_char(s):\n pass",