GitHub Repository Submission

When using GitHub mode, paste your repository URL below and click Save URL to store it. The saved URL will be automatically included with every message you send until you choose to clear it. Learn more

Your GitHub repository URL is saved. LSBot will automatically fetch your latest code from this repository for each message. To change the URL, clear it first and save a new one.

Exercise 1

After reading the problem description, what questions might you need clarified—either from the interviewer or by examining the test cases carefully? After exploring these questions, write up the P step in PEDAC, including inputs, outputs, explicit requirements, and implicit requirements.

Solution

Problem / Examples

  1. Will the input array always contain only integers? Could it include invalid values like null, strings, or floating-point numbers? In this case, the array will only contain integers.

  2. Is the array sorted? From the test cases it's obvious that the array is unsorted.

  3. What should the function return if the input array is empty? The problem doesn't specify behavior for empty input. Knowing the expected output for an empty array helps define the function's behavior. In this case, it should return null.

  4. What if there are multiple pairs that add up to 10? Another great question to ask is about handling multiple pairs. In this problem, we're guaranteed only to have one satisfying pair or none. We can appreciate, however, that without being certain of this constraint on the inputs, we would need to know how to handle multiple pairs that add to ten. How would we determine the "first" pair? In the array [3, 4, 6, 7], is [3, 7] the first pair, or is it [4, 6]? Both options could be valid, so the interviewer would need to clarify this.

  5. Can I include the same number twice? From the third test case, we see that even though the number 5 is in the array, we don't have a solution. This implies that we cannot use the same number twice. However, you should clarify with the interviewer what would happen if we had two '5's in the array (e.g., [1, 2, 5, 5, 6]). In this case, a valid solution would be [5, 5].

  6. Does the order of the elements in the result array matter? The test cases suggest that order matters, but this is something to verify with the interviewer. In this problem, the order does matter. The element appearing first in the original array should also be first in the result array. This means that in the first test case, [3, 7] is a valid solution, but [7, 3] is not.

  7. Can the numbers in the input array be negative or zero? Similar to our previous question, we can deduce this information from our test cases. Two of them include negative numbers in the input array, the second of which contains this negative number in the solution pair, [-5, 15]. We may still wish to ask about 0 being a possibility, but at least we know that it's possible for a number greater than 10 to make up a pair that adds to 10.

Problem:

  • Input: An array of numbers.
  • Output:
    • An array containing two numbers from the input array that add up to the target number, 10.
    • null if no suitable pair is found.
  • Rules:

    • Explicit requirements:
      • Find two numbers that sum to 10.
      • If no such numbers exist, return null.
      • There will be exactly one pair that sums to 10, or none.
    • Implicit requirements:
      • The input array will only contain integers.
      • The input array is unsorted.
      • We can't include the same number twice, unless it appears twice.
      • The order of elements in the result array should follow the order of these elements in the original array.
      • Numbers may be negative.

Hi! I'm LSBot. I can help you think through the selected exercise by giving you hints and guidance without revealing the solution. Your code from the editor will be automatically detected. Want to know more? Refer to the LSBot User Guide .

Detected solution
Loading...

Submit your solution for LSBot review.

Hi! I'm LSBot. Your code from the editor will be automatically detected. I'll review your solution and provide feedback to help you improve. Ask questions about your solution or request a comprehensive code review. Want to know more? Refer to the LSBot User Guide .

Detected solution
Loading...