After completing the Aptitude and Programming rounds, candidates must advance to Level 1: Basic Programming.
At this stage, participants are required to write programs for 5 programming questions.
The Zoho Basic Programming Round is an in-depth assessment aimed at evaluating a candidate's coding skills, understanding, and problem-solving capabilities.
Let's explore the key areas covered in this assessment.
Here's an overview of the Zoho Basic Programming Round:
Information | Detail |
---|---|
Total No of Sections |
1 |
Total No of Questions |
5 |
Total Time |
180 minutes |
Difficulty |
Moderate to High |
Elimination Round |
Yes |
Here's a snapshot of the Zoho Basic Programming Round syllabus:
Programming Assessment Syllabus | |||
---|---|---|---|
1 |
|
5 |
180 minutes (shared) |
After completing the Aptitude and Programming rounds, candidates must advance to Level 1: Basic Programming.
At this stage, participants are required to write programs for 5 programming questions.
1.
1. Write a function print_number_staircase(int n) that prints a pattern of numbers based on the input size n. The pattern is printed as a staircase, where each row starts with an incremented number and wraps around back to 1 when the number exceeds n.
C++
#include <iostream>
using namespace std;
void printNumberStaircase(int n) {
for (int i = 1; i <= n; i++) {
for (int j = i; j < i + n; j++) {
cout << (j - 1) % n + 1 << " ";
}
cout << endl;
}
}
int main() {
printNumberStaircase(5);
cout << endl;
printNumberStaircase(3);
return 0;
}
Java
public class NumberStaircase {
public static void printNumberStaircase(int n) {
for (int i = 1; i <= n; i++) {
for (int j = i; j < i + n; j++) {
System.out.print((j - 1) % n + 1 + " ");
}
System.out.println();
}
}
public static void main(String[] args) {
printNumberStaircase(5);
System.out.println();
printNumberStaircase(3);
}
}
Python
def print_number_staircase(n):
for i in range(1, n + 1):
row = []
for j in range(i, i + n):
row.append((j - 1) % n + 1)
print(" ".join(map(str, row)))
print_number_staircase(5)
print()
print_number_staircase(3)
Explanation of logic:
Example Outputs:
For n = 5:
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
For n = 3:
1 2 3
2 3 1
3 1 2
2.
2. Your task is to complete a function find_day(date, month, year) that takes three inputs: date, month, and year. The function should return the day of the week as a string (e.g., 'sunday', 'monday'). The function calculates the day of the week for the given date using the concept of odd days and leap years.
C++
#include <iostream>
#include <string>
using namespace std;
string find_day(int date, int month, int year) {
string days[] = {"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"};
int month_days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isLeap = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
if (isLeap) month_days[1] = 29;
int total_days = 0;
total_days += (year - 1) * 365 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400;
for (int i = 0; i < month - 1; i++) {
total_days += month_days[i];
}
total_days += date;
return days[total_days % 7];
}
int main() {
cout << find_day(15, 8, 1947) << endl;
cout << find_day(26, 1, 1950) << endl;
return 0;
}
Java
public class FindDay {
public static String find_day(int date, int month, int year) {
String[] days = {"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"};
int[] month_days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
boolean isLeap = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
if (isLeap) month_days[1] = 29;
int total_days = 0;
total_days += (year - 1) * 365 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400;
for (int i = 0; i < month - 1; i++) {
total_days += month_days[i];
}
total_days += date;
return days[total_days % 7];
}
public static void main(String[] args) {
System.out.println(find_day(15, 8, 1947));
System.out.println(find_day(26, 1, 1950));
}
}
Python
def find_day(date, month, year):
days = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
is_leap = (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
if is_leap:
month_days[1] = 29
total_days = 0
total_days += (year - 1) * 365 + (year - 1) // 4 - (year - 1) // 100 + (year - 1) // 400
total_days += sum(month_days[:month - 1])
total_days += date
return days[total_days % 7]
print(find_day(15, 8, 1947))
print(find_day(26, 1, 1950))
Explanation of Logic:
Example Outputs:
For find_day(15, 8, 1947)
the output is "friday".
For find_day(26, 1, 1950)
the output is "thursday".
3.
3. Your task is to complete a function is_valid_move(sourceRow, sourceCol, destRow, destCol, boardSize) that takes five inputs: the source position (sourceRow, sourceCol) of a queen, the destination position (destRow, destCol), and the size of the chessboard (boardSize). The function should return true if the move is valid for a chess queen, otherwise false.
C++
#include <iostream>
#include <cmath>
using namespace std;
bool is_valid_move(int sourceRow, int sourceCol, int destRow, int destCol, int boardSize) {
if (destRow < 0 || destRow >= boardSize || destCol < 0 || destCol >= boardSize) {
return false;
}
if (sourceRow == destRow || sourceCol == destCol || abs(sourceRow - destRow) == abs(sourceCol - destCol)) {
return true;
}
return false;
}
int main() {
cout << is_valid_move(2, 1, 1, 0, 5) << endl;
cout << is_valid_move(2, 1, 4, 2, 5) << endl;
cout << is_valid_move(2, 1, 3, 3, 5) << endl;
return 0;
}
Java
public class ChessQueen {
public static boolean is_valid_move(int sourceRow, int sourceCol, int destRow, int destCol, int boardSize) {
if (destRow < 0 || destRow >= boardSize || destCol < 0 || destCol >= boardSize) {
return false;
}
if (sourceRow == destRow || sourceCol == destCol || Math.abs(sourceRow - destRow) == Math.abs(sourceCol - destCol)) {
return true;
}
return false;
}
public static void main(String[] args) {
System.out.println(is_valid_move(2, 1, 1, 0, 5));
System.out.println(is_valid_move(2, 1, 4, 2, 5));
System.out.println(is_valid_move(2, 1, 3, 3, 5));
}
}
Python
def is_valid_move(sourceRow, sourceCol, destRow, destCol, boardSize):
if destRow < 0 or destRow >= boardSize or destCol < 0 or destCol >= boardSize:
return False
if sourceRow == destRow or sourceCol == destCol or abs(sourceRow - destRow) == abs(sourceCol - destCol):
return True
return False
print(is_valid_move(2, 1, 1, 0, 5))
print(is_valid_move(2, 1, 4, 2, 5))
print(is_valid_move(2, 1, 3, 3, 5))
Explanation of Logic:
sourceRow == destRow
sourceCol == destCol
abs(sourceRow - destRow) == abs(sourceCol - destCol)
Example Outputs:
For is_valid_move(2, 1, 1, 0, 5)
the output is true.
For is_valid_move(2, 1, 4, 2, 5)
the output is true.
For is_valid_move(2, 1, 3, 3, 5)
the output is false.
4.
4. Write a program to generate a numeric diamond pattern. The program takes a single input n (number of rows for the upper triangle). The pattern consists of two parts:
Upper Triangle: Starting from 1, each row prints numbers in descending order, aligned in a triangular shape, with spaces at the beginning of each row to form the diamond structure.
Lower Triangle: The numbers continue from the last row of the upper triangle, decreasing in size and aligned to mirror the upper triangle.
C++
#include <iostream>
#include <iomanip>
using namespace std;
void numeric_diamond(int n) {
int current = 1;
// Upper Triangle
for (int i = 1; i <= n; ++i) {
cout << string(n - i, ' ');
int temp = current + i - 1;
for (int j = 0; j < i; ++j) {
cout << temp--;
if (j < i - 1) cout << " ";
}
current += i;
cout << endl;
}
current -= n;
// Lower Triangle
for (int i = n; i >= 1; --i) {
cout << string(n - i, ' ');
int temp = current + i - 1;
for (int j = 0; j < i; ++j) {
cout << temp--;
if (j < i - 1) cout << " ";
}
current -= i;
cout << endl;
}
}
int main() {
int n = 4;
numeric_diamond(n);
return 0;
}
Java
public class NumericDiamond {
public static void numericDiamond(int n) {
int current = 1;
for (int i = 1; i <= n; i++) {
for (int space = 1; space <= n - i; space++) {
System.out.print(" ");
}
int temp = current + i - 1;
for (int j = 0; j < i; j++) {
System.out.print(temp--);
if (j < i - 1) System.out.print(" ");
}
current += i;
System.out.println();
}
current -= n;
for (int i = n; i >= 1; i--) {
for (int space = 1; space <= n - i; space++) {
System.out.print(" ");
}
int temp = current + i - 1;
for (int j = 0; j < i; j++) {
System.out.print(temp--);
if (j < i - 1) System.out.print(" ");
}
current -= i;
System.out.println();
}
}
public static void main(String[] args) {
int n = 4;
numericDiamond(n);
}
}
Python
def numeric_diamond(n):
current = 1
for i in range(1, n + 1):
print(" " * (n - i), end="")
temp = current + i - 1
for j in range(i):
print(temp, end="")
temp -= 1
if j < i - 1:
print(" ", end="")
current += i
print()
current -= n
for i in range(n, 0, -1):
print(" " * (n - i), end="")
temp = current + i - 1
for j in range(i):
print(temp, end="")
temp -= 1
if j < i - 1:
print(" ", end="")
current -= i
print()
numeric_diamond(4)
Explanation of Logic:
current
.current
is updated after each row.current
is decremented after printing each row.Example Output for n = 4:
1
3 2
6 5 4
10 9 8 7
10 9 8 7
6 5 4
3 2
1
5.
5. Write a program that generates a "snake pattern" for an n x n grid. The pattern alternates direction for each row, with odd rows incrementing and even rows decrementing.
C++
#include <iostream>
#include <iomanip>
using namespace std;
void snake_pattern(int n) {
int number = 1;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
// Print row left to right
for (int j = 0; j < n; j++) {
cout << setw(4) << number++;
}
} else {
// Print row right to left
int start = number + n - 1;
for (int j = 0; j < n; j++) {
cout << setw(4) << start--;
}
number += n;
}
cout << endl;
}
}
int main() {
int n = 5;
snake_pattern(n);
return 0;
}
Java
public class SnakePattern {
public static void snakePattern(int n) {
int number = 1;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
// Print row left to right
for (int j = 0; j < n; j++) {
System.out.printf("%4d", number++);
}
} else {
// Print row right to left
int start = number + n - 1;
for (int j = 0; j < n; j++) {
System.out.printf("%4d", start--);
}
number += n;
}
System.out.println();
}
}
public static void main(String[] args) {
int n = 4;
snakePattern(n);
}
}
Python
def snake_pattern(n):
number = 1
for i in range(n):
if i % 2 == 0:
# Print row left to right
for j in range(n):
print(f"{number:4}", end="")
number += 1
else:
# Print row right to left
start = number + n - 1
for j in range(n):
print(f"{start:4}", end="")
start -= 1
number += n
print()
# Test the function
snake_pattern(5)
Explanation:
number
.number
is incremented with each step.number + n - 1
.number
by n
after processing the row.Example Output for n = 4:
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
Example Output for n = 5:
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
21 22 23 24 25
1 of 1
What is the basic programming round in Zoho
The basic programming round is an important level in the Zoho recruitment process where candidates are tested on their coding skills.
Is the Zoho basic programming a compulsory round for all candidates?
Yes, the Zoho ba0sic programming round is compulsory for all candidates.
What languages can be used for the Zoho basic programming round?
Languages such as C, C++, Java, or Python can be used for Zoho basic programming round.
How many questions are there in the Zoho basic programming round?
There are 5 questions in the Zoho basic programming round.
How much time is given to complete the Zoho basic programming round?
Candidates are given 180 minutes (3 hours) to complete the Zoho basic programming round.
What is the difficulty level of the Zoho basic programming round?
The difficulty level of the Zoho basic programming round ranges from moderate to high.