Challenge - 5 Problems
Lookup Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:00remaining
Lookup time in an array
What is the output of the code showing the index lookup of value 7 in the array?
DSA Python
arr = [3, 5, 7, 9, 11] index = -1 for i in range(len(arr)): if arr[i] == 7: index = i break print(index)
Attempts:
2 left
💡 Hint
Look for the position where 7 appears in the list.
✗ Incorrect
The value 7 is at index 2 in the array. The loop finds it and breaks, so index is 2.
❓ Predict Output
intermediate1:30remaining
Lookup time in a linked list
What is the output of the code that searches for value 4 in a linked list and prints the found node's value?
DSA Python
class Node: def __init__(self, val): self.val = val self.next = None head = Node(1) head.next = Node(3) head.next.next = Node(4) head.next.next.next = Node(5) current = head found_val = None while current: if current.val == 4: found_val = current.val break current = current.next print(found_val)
Attempts:
2 left
💡 Hint
Traverse nodes until you find the value 4.
✗ Incorrect
The linked list nodes are checked one by one. When the node with value 4 is found, it is printed.
🧠 Conceptual
advanced1:00remaining
Time complexity comparison for lookup
Which data structure offers the fastest average lookup time for a key among these options?
Attempts:
2 left
💡 Hint
Think about average time to find an element by key.
✗ Incorrect
Hash maps provide average O(1) lookup time, faster than arrays or linked lists.
❓ Predict Output
advanced1:30remaining
Hash map lookup with collisions
What is the output of the code that simulates a simple hash map lookup with collisions?
DSA Python
hash_map = {0: 'apple', 1: 'banana', 2: 'cherry'}
key = 5
index = key % 3
result = hash_map.get(index, 'not found')
print(result)Attempts:
2 left
💡 Hint
Calculate key modulo size to find index.
✗ Incorrect
Key 5 modulo 3 is 2, so the value at index 2 is 'cherry'.
🧠 Conceptual
expert2:00remaining
Choosing data structure for frequent lookups and insertions
Which data structure is best suited for frequent insertions and lookups by key with minimal time complexity?
Attempts:
2 left
💡 Hint
Consider average time for both insert and lookup operations.
✗ Incorrect
Hash maps provide average O(1) time for insertions and lookups, better than linked lists, arrays, or BSTs.