Bird
0
0
DSA Cprogramming~10 mins

Subarray Sum Equals K Using Hash Map in DSA C - 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 variable that stores the count of subarrays.

DSA C
int count = [1];
Drag options to blanks, or click blank then click option'
A1
B0
C-1
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing count to 1 or negative values.
2fill in blank
medium

Complete the code to update the cumulative sum with the current array element.

DSA C
sum [1]= nums[i];
Drag options to blanks, or click blank then click option'
A-
B/
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
3fill in blank
hard

Fix the error in the condition that checks if (sum - k) exists in the hash map.

DSA C
if (hashMapContains(hashMap, sum [1] k)) {
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or multiplication instead of subtraction.
4fill in blank
hard

Fill both blanks to update the count and the hash map correctly.

DSA C
count += hashMapGet(hashMap, sum [1] k);
hashMapPut(hashMap, sum, hashMapGet(hashMap, sum) [2] 1);
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of subtraction in first blank or wrong operator in second blank.
5fill in blank
hard

Fill all three blanks to initialize the hash map, insert the base case, and iterate over the array.

DSA C
HashMap *hashMap = [1]();
hashMapPut(hashMap, 0, [2]);
for (int i = 0; i [3] n; i++) {
Drag options to blanks, or click blank then click option'
AhashMapCreate
B1
C<
DhashMapInit
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong function name, wrong base frequency (like 0), or wrong loop condition.