Rearrange a String Outside In
Updated
Problem statement
You are given a string text. Build a new string by taking the first remaining character, then the last remaining character, and continuing inward.
If the length is odd, append the middle character last.
Function
outsideIn(text: String) → StringExamples
Example 1
text = "abcdef"return = "afbecd"The pairs are a/f, b/e, and c/d.
Example 2
text = "abcde"return = "aebdc"The pairs are a/e and b/d, followed by the middle c.
Constraints
0 <= text.length <= 100000
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
Similar questions at other companies
- Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
- Alternate String EndsCapital One · OACapital One interview questions
- Run-Length String CompressionSalesforce · OASalesforce interview questions
- Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Count Binary SubstringsMicrosoft · OAMicrosoft interview questions
- Check a Repeated String as a SubsequenceQuince · OAQuince interview questions
- Reverse String In PlaceThe Walt Disney Company · OA · PHONE SCREENThe Walt Disney Company interview questions
- Lost MessagesSuperhuman · OASuperhuman interview questions
- Reverse a StringFlexTrade · OAFlexTrade interview questions
- Missing WordsVanguard · OAVanguard interview questions