The Lone Pair

MediumAcc. 87.4%
+30 XP 12

Precise Searching

In a large search space, you often want to stop the moment you find your target. When using nested loops, a break statement will exit the innermost loop, allowing the outer loop to continue to its next cycle.

The Assignment

Your function receives parameters max and targetSum.

  1. Write an outer for loop (i) from 1 to max.
  2. Write an inner for loop (j) from 1 to max.
  3. Inside the inner loop, check if the sum i + j is exactly targetSum.
  4. If the sum is matched:
    • Print the matching pair: (i, j)
    • Use break to exit the inner loop immediately.
  5. After the inner loop finishes (for every iteration of the outer loop), print a marker: "-" (a single dash).

01EXAMPLE 1

Inputmax = 5
Output- (2, 5) - (3, 4) - (4, 3) - (5, 2) -

Explanation: Stops inner loop at the first pair for each row.

Constraints

  • Use nested for loops.
  • Use a break statement inside the condition.
  • Log messages must match exactly.
LoopsControl FlowFundamentals
JavaScript
Loading...
3 Hidden

Input Arguments

max5
targetSum7

Expected Output

-
(2, 5)
-
(3, 4)
-
(4, 3)
-
(5, 2)
-

Click RUN to test your solution