FastPrepStretch Each Number Into Two Halves
Problems/Stretch Each Number Into Two Halves

Stretch Each Number Into Two Halves

DocuSign logoDocuSign● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A report from December 2019 describes an onsite task that turns each number of a list into its two halves. One sample: 14, 0 and -5 become 7, 7, 0, 0, -2, -3. Follow-up questions were about using an array and about the time cost.

The sample shows how a negative odd number splits but not a positive odd one. Here the first half is always x divided by 2, rounded toward zero. So 5 becomes 2, 3, matching how -5 becomes -2, -3. There are up to 1,000 numbers between -10^6 and 10^6, and you return the stretched list. Example 1 is the sample from the report. We wrote the other examples.

Our version is about 90% the same as the reported question.

You are given a list of integers nums. Stretch it: replace every number x with two numbers, its two halves, so the result is twice as long. The halves of each number stay next to each other, in the same order as the numbers in nums.

The two halves of x are found like this:

  • The first half is x divided by 2 with the fraction dropped, which rounds toward zero. For example, 7 gives 3 and -7 gives -3.
  • The second half is the rest: x minus the first half.

So an even number splits into two equal halves, and for an odd number the half nearer zero comes first: 7 becomes 3, 4 and -7 becomes -3, -4. The two halves always add up to x.

Function

stretchIntoHalves(nums: int[]) → int[]

Examples

Example 1

nums = [14,0,-5]return = [7,7,0,0,-2,-3]

14 splits into 7 and 7. 0 splits into 0 and 0. -5 is odd: the half nearer zero, -2, comes first, then the rest, -5 - (-2) = -3. The answer is [7,7,0,0,-2,-3].

Example 2

nums = [5,-1,8]return = [2,3,0,-1,4,4]

5 is odd: the half nearer zero is 2, then 5 - 2 = 3. -1 is odd: the half nearer zero is 0, then -1 - 0 = -1. 8 splits into 4 and 4. The answer is [2,3,0,-1,4,4].

Example 3

nums = [1000000,-999999]return = [500000,500000,-499999,-500000]

1,000,000 splits into 500,000 and 500,000. For -999,999 the half nearer zero is -499,999, and the rest is -500,000. The answer is [500000,500000,-499999,-500000].

Constraints

  • 0 <= nums.length <= 1000
  • -106 <= nums[i] <= 106

More DocuSign Onsite Interview questions

  • Count Binary SubstringsONSITE INTERVIEW · Seen Sep 2026
  • Two Positions That Add Up to a TargetPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Compress Consecutive Integer RangesONSITE INTERVIEW · Seen Aug 2026
  • JSON Schema Object ValidatorONSITE INTERVIEW · Seen Aug 2026
  • Most Transactions Kept Without Going NegativeONSITE INTERVIEW · Seen May 2025
  • Three-Part Splits With a Light MiddleONSITE INTERVIEW · Seen May 2025
  • Combine Two Sorted Lists Into OneONSITE INTERVIEW · Seen Apr 2022
  • Exact Palindrome CheckPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
  • Paired Words That Share a SubstringONSITE INTERVIEW · Seen Apr 2022
  • Reverse the Characters of a TextPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022

Similar questions at other companies

  • Plus OneDruva · ONSITE INTERVIEW
  • Rotate a Flat Image ClockwiseGoogle · ONSITE INTERVIEWGoogle interview questions
  • Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
  • Maximum Product of Three IntegersPelatro · ONSITE INTERVIEW
  • Exact-Sixty Dice Game ValueJane Street · ONSITE INTERVIEWJane Street interview questions
  • Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
  • Alternating Index Square SumAccenture · ONSITE INTERVIEWAccenture interview questions
  • Moving Cost by Volume and CategoryWayfair · ONSITE INTERVIEWWayfair interview questions
  • Add One to a Number Represented as DigitsOracle · ONSITE INTERVIEWOracle interview questions
  • Streaming Entropy, Part 1: Batch EntropyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions

Interview reports that mention this question

  • DocuSign SWE Intern Interviews: 27 Experiences (Part 2 of 2)

DocuSign interview experiences

  • DocuSign SWE Intern OA Questions: 53 Experiences (Part 1 of 2)
All DocuSign interview questionsSee DocuSign hiring insights
Saved
class Solution {
    public int[] stretchIntoHalves(int[] nums) {
        // Write your code here.
    }
}
Checking account…