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- A. 1
- B. 3
- C. 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- A Value Object is modelled as a frozen dataclass. What does this print? python from dataclasses import dataclass, FrozenInstanceError…
- This Singleton caches its instance in new. What does it print? python class Settings: instance = None def new(cls, args): if cls.instance…
- Module report.py does from pricing import getrate and calls getrate() inside build(). A unit test for build() uses…
- A faulty merge M of feature into main was undone with git revert -m 1 M. The feature team later fixes the bug with a new commit on feature…
- You run git stash pop and it reports a merge conflict in f.txt. What happens to the stash entry?
- During git rebase -i, what is the difference between marking a commit 'squash' and marking it 'fixup'?