less than 1 minute read

Given a string s and an integer k, rearrange s into k rows so that s can be read vertically (top-down, left to right).

Constraints

  • n ≤ 10,000 where n is the length of s
  • k ≤ 1,000

https://binarysearch.com/problems/Vertical-Cipher

Examples

Example 1

Input

  • s = abcdefghi
  • k = 5

Output

  • answer = ['af', 'bg', 'ch', 'di', 'e']

Explanation

This reads vertically as:

["af",
 "bg",
 "ch",
 "di",
 "e"]

Solution

Leave a comment