0
0
DSA Pythonprogramming~10 mins

Two Sum Problem Classic Hash Solution in DSA Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the dictionary for storing seen numbers.

DSA Python
seen = [1]
Drag options to blanks, or click blank then click option'
A[]
B{}
C()
Dset()
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list or set instead of a dictionary.
Using parentheses which create a tuple, not a dictionary.
2fill in blank
medium

Complete the code to iterate over the list with index and value.

DSA Python
for [1], num in enumerate(nums):
Drag options to blanks, or click blank then click option'
Ai
Bvalue
Cindex
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using the value variable name instead of index.
Using a variable name that is not descriptive or inconsistent.
3fill in blank
hard

Fix the error in checking if the complement exists in the dictionary.

DSA Python
if [1] in seen:
Drag options to blanks, or click blank then click option'
Anum
Bi
Ctarget - num
Dseen[num]
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if the current number num is in seen instead of the complement.
Using the index i instead of the complement.
4fill in blank
hard

Fill both blanks to return the indices of the two numbers that add up to target.

DSA Python
return [seen[[1]], [2]]
Drag options to blanks, or click blank then click option'
Atarget - num
Bi
Cnum
Dseen[num]
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the current number instead of its index.
Swapping the order of indices incorrectly.
5fill in blank
hard

Fill all three blanks to add the current number and its index to the dictionary.

DSA Python
seen[[1]] = [2]

# After loop ends
return [3]
Drag options to blanks, or click blank then click option'
Anum
Bi
C[]
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using the index as key instead of the number.
Returning an empty list instead of None.