FastPrepZigzag Conversion
Problems/Zigzag Conversion

Zigzag Conversion

Tripjack logoTripjack● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This comes from an in-person Tripjack interview for an SDE-1 role. The first technical round was a coding round with two questions, and this was one of them. The report gives only the well-known name of the problem.

The report gives no limits or examples, so this version uses the usual rules: write the string down and up across the rows, then read the rows from top to bottom. One row leaves the string unchanged. The string has up to 1,000 characters.

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

You are given a string s and a number of rows numRows. Write the characters of s in a zigzag over the rows, numbered 0 to numRows - 1 from top to bottom:

  • Put the first character in row 0.
  • Go down one row for each next character until you reach the bottom row, numRows - 1.
  • Then go up one row for each next character until you reach row 0 again. Then go down again, and so on until every character is placed.

Now read the rows from top to bottom. Read the characters of each row in the order they were placed there. Return the string you read.

If numRows is 1, every character goes in row 0, so the answer is s itself.

Function

convert(s: String, numRows: int) → String

Examples

Example 1

s = "FASTPREP"numRows = 3return = "FPATRPSE"

The characters go to rows 0, 1, 2, 1, 0, 1, 2, 1. So row 0 gets F and P, row 1 gets A, T, R and P, and row 2 gets S and E.

Reading the rows from top to bottom gives FP + ATRP + SE = FPATRPSE.

Example 2

s = "ABCDEFG"numRows = 4return = "AGBFCED"

The characters go to rows 0, 1, 2, 3, 2, 1, 0. Row 0 gets AG, row 1 gets BF, row 2 gets CE and row 3 gets D.

Together they read AGBFCED.

Example 3

s = "a.B,c"numRows = 1return = "a.B,c"

With one row, every character goes in row 0 in its original order, so the string does not change.

Constraints

  • 1 <= s.length <= 1000
  • s contains only English letters (lowercase and uppercase), ',' and '.'.
  • 1 <= numRows <= 1000

More Tripjack Onsite Interview questions

  • Reconstruct ItineraryONSITE INTERVIEW · Seen Nov 2026
  • Wildcard MatchingONSITE INTERVIEW · Seen Nov 2026
  • Jump Game IIONSITE INTERVIEW · Seen Aug 2026
  • Number of IslandsONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Sliding Items on a Circular RingIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
  • Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
  • Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • In-Memory Vault File SystemHarvey · ONSITE INTERVIEWHarvey interview questions
  • Digit-Coded Card ValidationCapital One · ONSITE INTERVIEWCapital One interview questions
  • Query JSON Records with WHERE and ORDER BYGitHub · ONSITE INTERVIEW
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Generate Word Guess FeedbackAtlassian · ONSITE INTERVIEWAtlassian interview questions
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
All Tripjack interview questionsSee Tripjack hiring insights
Saved
class Solution {
    public String convert(String s, int numRows) {
        // Write your code here.
    }
}
Checking account…