Avinash Paritala
BAN USER- 0of 0 votes
AnswersImagine you have a row of numbers like below(a traiangle) .By starting at the top of the triangle find the maximum number in each line and sum them up example below
- Avinash Paritala in India
5
9 6
4 6 8
8 7 15
Answer I.e. 5+9+8+7 = 29
writw a code to find the maximum total from top to bottom. Assume triangle can have at most 100000 rows.
Input Output specifications
Input Specification
A string of n numbers (where 0<=n<=10^10)
eg.5#9#6#4#6#8#0#7#1#5
Output Specification
A sum of the max numbers in each line (as string ) or Output invalid in case of invalid input/triangle
Examples
eg1.
Input :5#9#6#4#6#8#0#7#1#5
Output:29
eg 2 .
Input :5#9#6#4#6#8#0#7#1
Output:invalid
eg 2 .
Input :5#9##4#6#8#0#7#1
Output:invalid| Report Duplicate | Flag | PURGE
Google Software Engineer - -1of 1 vote
AnswersTwo political parties are contesting in the elections in the N number of states in the country. Each party wins some seats every year in each state. After the current elections are over we have the result of both the parties with their number of seats won in each state.
- Avinash Paritala in India
The two parties are considered equal if they win the same number of seats in the N states in any order. Otherwise, they are considered unequal. Input/Output Specifications
INPUT: 1) It is an array of N integers depicting number of seats won by party one in each state. 2) It is an array of N integers depicting number of seats won by party two in each state. 3) An integer containing number of states (N).
OUTPUT: Equal/Unequal/Invalid
Equal: if political parties are equal Unequal: if political parties are unequal Invalid: if any party has invalid number of seats in any state
Examples
Example 1:
Two parties contested in seven states Seats won by party one in all the seven states: {12,11,5,2,7,5,-11} Seats won by party two in all the seven states: {5,12,5,7,11,2,11} The party two has an invalid number of winning seats(-11). So the output will be "Invalid".
Input :
1) {12,11,5,2,7,5,-11}
2) {5,12,5,7,11,2,11}
3) 7
Output: Invalid
Example 2:
Two parties contested in seven states Seats won by party one in all the seven states: {12,11,5,2,7,5,11} Seats won by party two in all the seven states: {5,12,5,7,11,2,11} Both the parties are equal because they have got 11(2 times each), 5(2 times each),7( 1 time each), 2(1 time each), 12( 1 time each other outputs (0 times each).
Input :
1) {12,11,5,2,7,5,11}
2) {5,12,5,7,11,2,11}
3) 7
Output: Equal
Example 3:
Input :
{12,11,5,2,7,5,11}
{5,0,5,7,11,2,11}
7
Output: Unequal| Report Duplicate | Flag | PURGE
Google Software Engineer - 1of 1 vote
AnswersRahul is playing a very interesting game. He has some N different type of match boxes. All match boxes may have different number of matchsticks (S1, S2, S3... Sn).
- Avinash Paritala in India
Rahul chooses two random numbers F and K. K should be less than N. The game is that Rahul wants to select any K match boxes out of N match boxes such that total number of matchsticks in these K selected match boxes should be multiple of F.
At the sametime Rahul wants that sum matchsticks of all the selected match boxes should be minimum possible.
Input Specifications:
1) Array S = {S1,S2,S3,...Sn} of size N corresponding to the number of match sticks in N matchboxes(0<=N<=1000}
2) F-Value (as explained above)
3) K-Value ( as explained above)
Output:
1 2 3 4 5 Here 3 is the number of matchsticks in matchbox I II III IV V minimum possible total number of matchsticks such that the conditioned explained in the problem statement is satisfied. Output -1 if it is not possible or invalid input.
For example, there are 5 match boxes i.e., N = 5
Let's say K is 3 (Rahul has to choose any 3 matchboxes)
Let's say F is 5(sum of matchsticks in 3 selected matchboxes should be multiple of 5).
Rahul can choose II, III and V matchboxes which would give the total sum of 10 which is multiple of F i.e., 5. And 10 is the minimum possible matchsticks possible in the above case.
So you have to answer the minimum possible matchstick(sum of the matchsticks in the selcted matchboxes) but the conditions given above should be satisfied.| Report Duplicate | Flag | PURGE
Google Software Engineer