Zoho Day 3

1.
Problem statement:
Reverse the string.
E.g.:
Input: one two three
Output: three two one

Input: I love india
Output: india love I 
 
2.
Problem statement:
Find the logic behind the output and code for it.
Input:
Number of elements in set 1: 4
Elements are: 9, 9, 9, 9
Number of elements in set 2: 3
Elements are: 1,1,1
Output:
1, 0, 1, 1, 0

Input:
Number of elements in set 1: 11
Elements are: 7,2,3,4,5,3,1,2,7,2,8
Number of elements in set 2: 3
Elements are: 1,2,3
Output:
7,2,3,4,5,3,1,2,8,5,1 
 
 
3.
Problem statement:
Print the pattern.

Input:
5

Output:
         *
       * *
     * * *
   * * * *
 * * * * *
   * * * *
     * * *
       * *
         *

4.
Problem statement:
A man his driving car from home to office with X petrol. There are N number of petrol bunks in the city
with only few capacities and each petrol is located in different places For one km one liter will consume.
So he fill up petrol in his petrol tank in each petrol bunks. Output the remaining petrol if he has or tell
him that he cannot travel if he is out of petrol.

Input:
Petrol in car: 2 Liters
Petrol bunks: A B C
Distance from petrol each petrol bunks: 1, 5, 3
Capacities of each petrol bunk: 6, 4, 2

Output:
Remaining petrol in car is 5 liters 
 
 
 
5.
Problem statement:
Recursively print all sentences that can be formed from list of word lists.

Given a list of word lists How to print all sentences possible taking one word 
from a list at a time via recursion?

Example:
Input:
       {{"you", "we"},
       {"have", "are"},
       {"sleep", "eat", "drink"}}

Output:

you have sleep
you have eat
you have drink
you are sleep
you are eat
you are drink
we have sleep
we have eat
we have drink
we are sleep
we are eat
we are drink 
 
 
 
6.
Problem statement:
Remove unbalanced parentheses in a given expression.
E.g.:
Input: ((abc)((de))
Output: ((abc)(de))

Input: (((ab)
Output: (ab)

Comments

Popular Posts