Interview Question ZigZag Conversion

Last update: 11/20/2016 3:36:00 PM

By Fatih KABAKCI

The problem is to convert a string to a new pattern which is called zigzag that shapes characters in rows. Algorithm starts to run by asking the user that how many rows the user would like to input, then it converts the string a zigzag pattern that split all characters in rows.

Problem #6 - ZigZag Conversion

Description: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility).

P A H N
A P L S I I G
Y I R

And then read line by line: "PAHNAPLSIIGYIR"

Write the code that will take a string and make this conversion given a number of rows:.

Difficulty: Easy

Solution in Java

The solution can be implemented as imagining of the variable deep travels like a sinusoidal curve as increasing first from 0 to number of rows, and then again it decreases from number of rows to 0. Then, each character is stored in the related deep level during this period that looks like below.

A programming language is a formal constructed language designed to communicate instructions to a machine, particularly a computer. It can be used to create programs to control the behavior of a machine.
Java,C,
C++,C#

Computer hardware is the collection of physical elements that constitutes a computer system. Computer hardware refers to the physical parts or components of a computer such as the monitor, memory, cpu.

Web development is a broad term for the work involved in developing a web site for the Internet or an intranet. Html,Css,JavaScript,ASP.Net,PHP are one of the most popular technologies.
J2EE,Servlet,
JSP,JSF,
ASP

Mobile application development is the process by which application software is developed for low-power handheld devices, such as personal digital assistants, enterprise digital assistants or mobile phones.
J2ME

A computer network or data network is a telecommunications network that allows computers to exchange data. In computer networks, networked computing devices pass data to each other along data connections.

An operating system is software that manages computer hardware and software resources and provides common services for computer programs. The OS is an essential component of the system software in a computer system.
Linux,Windows