CS FundamentalsVery hardProduct-company placement

For the same findpair function (two nested for loops, an if that returns (i, j) when a pair matches, and return None after the loops), what is the minimum number of test calls for 100% branch coverage?

For the same find_pair function (two nested for loops, an if that returns (i, j) when a pair matches, and return None after the loops), what is the minimum number of test calls for 100% branch coverage?
def find_pair(a, target):
    for i in range(len(a)):
        for j in range(i + 1, len(a)):
            if a[i] + a[j] == target:
                return (i, j)
    return None
  1. A. 1
  2. B. 3
  3. C. 4
  4. D. 2

Correct answer: D. 2

The if's True outcome returns immediately, so that run never exits the outer loop normally; the loop-exit outcomes and return None need a run where no pair matches. One matching and one non-matching call (e.g. target 9 and target 100 on [1, 2, 3, 4, 5]) cover every branch.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic