0% found this document useful (0 votes)
354 views12 pages

Juspay

The document outlines ten distinct programming problems, each with specific input and output requirements. Problems range from counting stars between bars in a string to calculating maximum sweetness from a binary tree of fruits. Each problem includes constraints, sample inputs, and expected outputs to guide implementation.

Uploaded by

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

Juspay

The document outlines ten distinct programming problems, each with specific input and output requirements. Problems range from counting stars between bars in a string to calculating maximum sweetness from a binary tree of fruits. Each problem includes constraints, sample inputs, and expected outputs to guide implementation.

Uploaded by

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

Question 1: Stars Between Bars

Given a string s consisting of stars “*” and bars “|” ,an array of starting indices
starIndex, and an array of ending indices endIndex, determine the number of stars
between any two bars within the substrings between the two indices inclusive .
NOTE that in this problem indexing starts at 0.

 A Star is represented as an asterisk [*=ascii decimal 42]

 A Bar is represented as a Pipe [“|”=ascii decimal 124]

Example

s=’|**|*|’
n=2
startIndex=[0,0]
endIndex=[4,5]

 For the first pair of indices (0,4) the substrings is “|**|*” . There are 2 stars

between a pair of bars

 For the second pair of indices (0,5) the substring is “|**|*|” and there are

2+1=3 stars in between the bars.

 Both of the answers are returned to the array [2,3].

Constraints

 1 <= n <= 105


 1 <= StartIndex[i] <= endIndex[i]

 Each Character of s is either “*” or “|”

Input Format for Custom testing

First line contains a string S. The next line contains an integer n , the no.of
elements in startIndex and endIndex. Each line i of the n subsequent lines contains
an integer of startIndex. Each line i of the n subsequent lines contains an integer of
endindex.

Sample Input

*|*| → s=”*|*|”
1 → size of startindex[] and endIndex[] is 1.
0 → startindex = 0
2 → endindex = 2

Sample output:

Question 2: Vampire Battle

Stephan is a vampire. And he is fighting with his brother Damon. Vampires get
energy from human bloods, so they need to feed on human blood, killing the
human beings. Stephan is also less inhuman, so he will like to take less life in his
hand. Now all the people’s blood has some power, which increases the powers of
the Vampire. Stephan just needs to be more powerful than Damon, killing the least
human possible. Tell the total power Stephan will have after drinking the bloods
before the battle.

Note : Damon is a beast, so no human being will be left after Damon drinks
everyone’s blood. But Stephan always comes early in the town.

Input Format:

 First line with the number of people in the town, n.

 Second line with a string with n characters, denoting the one digit power in

every blood.

Output Format:

Total minimum power Stephan will gather before the battle.

Constraints:

 1 <= n <= 10^4

Sample input:

 6

 093212

Sample output
 9

Explanation:

Stephan riches the town, drinks the blood with power 9. Now Damon cannot reach
9 by drinking all the other bloods.

Question 3 : Duplicates

The principal has a problem with repetitions. Everytime someone sends the same
email twice he becomes angry and starts yelling. His personal assistant filters the
mails so that all the unique mails are sent only once, and if there is someone
sending the same mail again and again, he deletes them. Write a program which
will see the list of roll numbers of the student and find how many emails are to be
deleted.

Input Format:

 First line takes n, which is the total no. of mails recieved.

 Second line takes the n no. of email id as input./li>

Output Format:

Total no. of duplicate email id’s to be deleted.

Constraints:
 1 <= n <= 10^4

Sample input:

 6

 133433

Sample output

 3
Question 4 : Coin Game

Raman was playing a game, he starts with x coins. Now in every step, he wins and
loses and he has to get the money or pay the money as needed. He came in contact
with a psychic who can see the future and the Psychic predicted the outcomes after
each step. Now Raman wants to start the game with the minimum wage where he
doesn’t run out of money. Help Raman to find what money he should start with.
The only rule to keep playing is not going in a credit situation.

Input Format:

 First line with n, number of steps in the game

 Next n lines, n integers denoting outcomes of every game. Positive means

winning and negative means losing that money.

Output Format:
 One single integer denoting the minimum amount to start with

Constraints:

 Number of steps<=10^9

 -1000<=Money needed in each step<=1000

Sample Input:

4
2
-9
15
2

Sample Output:

Explanation:

If he starts with 7 rupees, then after steps : 7 ->9 -> 0-> 15 -> 17.

Question 5: Problem Statement


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: An 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.

Constraints
2<=k<=106
1<=v<=106

Question 6: Problem Statement


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.

Question 7: Problem Statement


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.

Question 8: Problem Statement


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.
Question 9: Problem Statement
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.


Question 10: Problem Statement
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