Juspay
Juspay
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.
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
For the second pair of indices (0,5) the substring is “|**|*|” and there are
Constraints
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:
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:
Second line with a string with n characters, denoting the one digit power in
every blood.
Output Format:
Constraints:
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:
Output Format:
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:
Output Format:
One single integer denoting the minimum amount to start with
Constraints:
Number of steps<=10^9
Sample Input:
4
2
-9
15
2
Sample Output:
Explanation:
If he starts with 7 rupees, then after steps : 7 ->9 -> 0-> 15 -> 17.
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.
Constraints
2<=k<=106
1<=v<=106
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.
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].
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.
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.
Input Format
The first line of the input contains an integer N denoting the number of nodes.
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:
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.
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.
Output Format
Print a single integer the maximum amount of sweetness you can get from the
collected fruits.