Zigzag Conversion
Medium About 15 min Free, no account needed
Write the string in a zigzag over n rows, then read row by row.
The brief
Write s in a zigzag pattern over numRows rows (down the rows, then
diagonally back up, repeating), and return the characters read row by row.
"PAYPALISHIRING" over 3 rows:
P A H N
A P L S I I G
Y I Rreads "PAHNAPLSIIGYIR".
numRows == 1 has no zigzag at all, naive direction-flipping code divides by
zero or bounces out of range there. The hidden tests cover one row and more
rows than characters.
Starter code
using System;
public class Solution
{
// TODO: return the characters of the zigzag pattern, read row by row.
public string ConvertZigzag(string s, int numRows)
{
throw new NotImplementedException();
}
}How it is graded
Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.
What it practices
- String processing
- Parse, scan and match text character by character with correct edge cases.
Related katas
- Decode String Medium Free Expand k[encoded] patterns, nesting included.
- Count Substring Occurrences Medium Free Count overlapping occurrences by comparing characters, not slicing strings.
- Hex Checksum Medium Free Sum the bytes of a hex string with nibble arithmetic, not substrings.
- Integer to Roman Medium Free Write Roman numerals the way Romans did - greedily.