Skip to main content
added 43 characters in body
Source Link
Ginger
  • 6k
  • 5
  • 20

Find the first run of numbers summing to n

Given as input a number n and a sequence of digits 0-9 (which may be taken as a string or a list), find the first contiguous subsequence of digits in the sequence that sums to n and output the start and end indexes. You may use zero- or one-based indexing. If no such subsequence exists, your program may output any constant value.

Examples

These examples use zero-based indexing.

Input: 10 123456789
Output: 0 3
Input: 32 444444444
Output: 0 7
Input: 33 444444444
Output: No solutions

Find the first run of numbers summing to n

Given as input a number n and a sequence of digits 0-9, find the first contiguous subsequence of digits in the sequence that sums to n and output the start and end indexes. You may use zero- or one-based indexing. If no such subsequence exists, your program may output any constant value.

Examples

These examples use zero-based indexing.

Input: 10 123456789
Output: 0 3
Input: 32 444444444
Output: 0 7
Input: 33 444444444
Output: No solutions

Find the first run of numbers summing to n

Given as input a number n and a sequence of digits 0-9 (which may be taken as a string or a list), find the first contiguous subsequence of digits in the sequence that sums to n and output the start and end indexes. You may use zero- or one-based indexing. If no such subsequence exists, your program may output any constant value.

Examples

These examples use zero-based indexing.

Input: 10 123456789
Output: 0 3
Input: 32 444444444
Output: 0 7
Input: 33 444444444
Output: No solutions
Source Link
Ginger
  • 6k
  • 5
  • 20

Find the first run of numbers summing to n

Given as input a number n and a sequence of digits 0-9, find the first contiguous subsequence of digits in the sequence that sums to n and output the start and end indexes. You may use zero- or one-based indexing. If no such subsequence exists, your program may output any constant value.

Examples

These examples use zero-based indexing.

Input: 10 123456789
Output: 0 3
Input: 32 444444444
Output: 0 7
Input: 33 444444444
Output: No solutions