Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
23 views3 pages

Questions

The document outlines five coding problems related to string manipulation, matrix sorting, tree structures, median calculation, and maximizing fruit sweetness in a binary tree. Each problem includes a clear input and output format, specifying the operations required to solve the tasks. The problems are designed to test algorithmic thinking and coding skills.

Uploaded by

stmonika15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Questions

The document outlines five coding problems related to string manipulation, matrix sorting, tree structures, median calculation, and maximizing fruit sweetness in a binary tree. Each problem includes a clear input and output format, specifying the operations required to solve the tasks. The problems are designed to test algorithmic thinking and coding skills.

Uploaded by

stmonika15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Juspay Coding Test Questions & Answers

Problem Statement 1
You are given a string with alphabets. You need to convert the string to lowercase and check if the
string is a palindromic one.
If the string is a palindrome, print the length of the palindromic string. If that string is a non-
palindromic one, print the ASCII value of the first character of the alphabet in the given string.
Input Format
The input consists of a single string containing only alphabetic characters (both uppercase and
lowercase).
Output Format
Print the Length of the palindromic string if it is a palindrome after performing the above operations.
Otherwise, print the ASCII value of the first character.
Problem Statement 2
A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or
leftmost column and going in the bottom-right direction until reaching the matrix's end.
For example, the matrix diagonal starting from mat[2][0], where mat is a 6 x 3 matrix, includes cells
mat[2][0], mat[3][1], and mat[4][2].
Given an m x n matrix mat of integers, sort each matrix diagonal in ascending order and return the
resulting matrix.
Input Format
The first line contains two integers, M and N, representing the number of rows and columns in the
matrix.
The next M lines each contain N integers, representing the elements of the matrix mat. Each line
corresponds to a row in the matrix.
Output Format
Print the Diagonally sorted matrix. Each row of the matrix should be printed on a new line.
Problem Statement 3
Ronnie is given N coins, each having some value, and provided with a task. In the task, Ronnie has to
first arrange the coins in a sorted fashion. After that, he has to set the coins in the form of a tree.
After forming the tree, he has to find the maximum possible absolute value of the difference in that
tree, as that will be the profit he will make.
Your task is to help Ronnie find the maximum profit.
Input Format
The first line of the input contains an integer N denoting the number of nodes.
The next line of the input contains N integers.
Output Format
Display the maximum profit that Ronnie can make.
Problem Statement 4
Archan is a professor at the Academy Of Technology. One day, he calls his student Niladri to play an
interesting game. He asked Niladri to imagine an empty bucket. He then does k queries. In each query,
he asks Niladri to do either of the following operations:
Add a number v to the bucket.
Get the median of all numbers added to the bucket.
Niladri needs to answer Archan only in the type 2 query. Can you help Niladri to do so?
Note: Answer within one decimal place of the actual answer will be accepted.
Input Format
The first line contains k, which is the number of queries that Archan will ask. K subsequent lines
follow.
Each line contains the type of query whether it is “add” or “get” followed by a space and then the
value v if it's an “add” query.
The first query will always be “add”. There will be at least one “get” query.
Output Format
The output contains several lines(one or more), each denoting the answer to each “get” query.
The answer should always be formatted to one decimal place.
Problem Statement 5
A park in the city has N trees numbered from 1 to N connected by N-1 pavements. This structure
resembles a binary tree rooted at tree '1' where trees represent the vertices and pavements represent its
edges.
Each tree has a fruit on it. Some of the fruits are sweet, while others are bitter. The ith tree (1 <= i <=
N) has a fruit of sweetness ai. If the fruit is bitter, the value of ai will be negative.
You went to the park to collect fruits. You cannot visit any tree more than once and will have to
collect the fruit from each tree you visit from the starting position of your choice. You can decide to
return home with all the fruits you collected at any point. Find the maximum value of sweetness that
you can collect.
Input Format
The first line contains a single integer N, denoting the number of trees in the park.
The second line contains N integers a1, a2, …, aN, denoting the sweetness of fruit on each of the N
trees.
The next N lines describe the binary tree structure of the park. The ith line contains two integers, li
and ri, denoting the indices of the left and right children of the ith vertex, respectively. If some child
doesn't exist, then the number “-1” is set instead.
It is guaranteed that the given graph is a binary tree rooted at vertex 1.
Output Format
Print a single integer the maximum amount of sweetness you can get from the collected fruits.

You might also like