Interleave Array Halves
Updated
Problem statement
You are given an array coupons of even length 2m. Interleave its first and second halves, taking one element from the first half followed by the matching element from the second half.
Return [coupons[0], coupons[m], coupons[1], coupons[m + 1], ...]. Keep the order within each half. Equal coupon numbers remain separate elements.
For this exercise, assume an empty input returns an empty array. Return a new array and leave coupons unchanged.
Function
interleaveHalves(coupons: int[]) → int[]Examples
Example 1
coupons = [4,4,4,4,8,3,5,9]return = [4,8,4,3,4,5,4,9]The first half is [4,4,4,4] and the second half is [8,3,5,9]. Pairing their elements in order gives [4,8,4,3,4,5,4,9]; all four copies of 4 are kept.
Example 2
coupons = [1,2,10,20]return = [1,10,2,20]The halves are [1,2] and [10,20]. Take 1, then 10, then 2, then 20.
Constraints
- For this exercise, assume 0 <= coupons.length <= 2000.
- The length of coupons is even.
- For this exercise, assume 0 <= coupons[i] <= 10^9.
More Morgan Stanley Online Assessment questions
- Three-Resource 0/1 KnapsackOA · Seen Sep 2026
- Maximum Concurrent ProcessesOA · ONSITE INTERVIEW · Seen Sep 2026
- Maximum Total of Nonadjacent RatingsOA · Seen Jul 2026
- Count Shipment SchedulesOA · Seen Apr 2026
- Delete and EarnOA · Seen Apr 2026
- Get Patch SequenceOA · Seen Feb 2025
- String Subsequences 🐳OA · Seen Mar 2024
- Binary Tree Level OrderOA · Seen Feb 2024
- Merge IntervalsOA · Seen Feb 2024
- Format Chemical SymbolsOA · Seen Feb 2023
Similar questions at other companies
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Count Valid Square PairsAuxoAI · OA
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Two SumAmazon · OA · PHONE SCREEN
- Count Strictly Increasing Contiguous WindowsIBM · OAIBM interview questions
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Server InvestmentRippling · OARippling interview questions
- Book Reading EveningsGoogle · OAGoogle interview questions
- Minimum Index Distance Between Person and CakeSnowflake · OA · PHONE SCREENSnowflake interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
Interview reports that mention this question
Morgan Stanley interview experiences
- Morgan Stanley New Grad Technology Analyst: 2 Experiences
- Morgan Stanley Intern Oldest Loops: 5 Experiences (Part 5 of 5)
- Morgan Stanley Intern OOP Loops: 5 Experiences (Part 4 of 5)
- Morgan Stanley Intern Earlier Loops: 5 Experiences (Part 3 of 5)
- Morgan Stanley Intern Tech Rounds: 5 Experiences (Part 2 of 5)