Competitive Coding Club
In 2024, I co-founded the Competitive Coding Club at Westfield High School, and I’m its vice president. The club runs coding workshops and supports students who are getting started in competitive programming and computer science.
What competitive programming is
In a programming contest, each problem describes a task and shows a few examples. You write a program that solves it. A judge then runs your program on test cases you never see, and it only counts if every answer is right and it finishes within the time limit.
So a correct program is not always enough. The idea behind it has to be fast enough for the largest test, and that is most of what there is to learn.
The problem Given a list of numbers and a target, find two numbers in the list that add up to the target. The judge runs each program on six lists, from ten numbers to a million, and allows one second for each.
Check every pair
for i in range(n):
for j in range(i + 1, n):
if a[i] + a[j] == target:
return i, j
- 10 numbers Accepted, under 0.01 s
- 100 numbers Accepted, under 0.01 s
- 1,000 numbers Accepted, under 0.01 s
- 10,000 numbers Accepted, 0.5 s
- 100,000 numbers Over the time limit
- 1,000,000 numbers Over the time limit
4 of 6 tests passed
Remember what you have seen
seen = {}
for i, x in enumerate(a):
if target - x in seen:
return seen[target - x], i
seen[x] = i
- 10 numbers Accepted, under 0.01 s
- 100 numbers Accepted, under 0.01 s
- 1,000 numbers Accepted, under 0.01 s
- 10,000 numbers Accepted, under 0.01 s
- 100,000 numbers Accepted, under 0.01 s
- 1,000,000 numbers Accepted, 0.01 s
6 of 6 tests passed