Sie sind auf Seite 1von 4

Question 1:

During the war the enemy battalion has planted a bomb in your bunker. Your
informer has sent you a message of the enemy which contains a list having N
numbers and a key (K). The numbers have to be used to construct a sequence to
defuse the bomb. According to your informer, the logic to extract the sequence
from the whole message is to replace each number with the sum of next K
numbers, if the value of K is positive. When the value of K is negative, the number
is replaced by the sum of the previous K numbers. The series of numbers is
considered in a cyclic fashion for the last K numbers.
Write an algorithm that finds the sequence to defuse the bomb.
The input to the function/method consists of three arguments-
Size, an integer representing the size of the list (N). Key, an integer representing
the key (K).
Question 2:
An image is represented by a m*n matrix of integers where each integer represents
a pixel value. Write an algorithm to rotate an image by 90 degree left or right
according to the value of a flag variable. If the flag value is 0, then rotate to the left
and the flag value is 1, then rotate to right.
The input to the method consists of four arguments-
Img a matrix of integers representing the pixel of the image
Rows an integer representing the number of rows(m)
Columns an integer representing the number of columns(n)
Flag an integer representing the rotation of the image.
Return a matrix of integers representing the pixel of the image according to the
value of the flag variable.
Question 3:
The input to the function methods consists of three arguments-
Size an integer representing the list of the list (N)
Key an image representing the key(K)
Message representing the list of integers
Return a list of integers representing the sequence to define the bomb.
Question 4

Mr. Jason has captured your friend and has put a collar around is neck. He has
locked the collar with a given “locking key”. Now it can only be opened with an
“Unlocking key”. Your friend has seen the “ locking key” but he doesnot know
how to find the “unlocking key”. You can calculate the “unlocking key” if you
have the “locking key”, because it will be the smallest permutation of the digits of
the “locking key” and will never start with zero.

Help your friend write an algorithm that takes the “locking key” as an input and
outputs the “unlocking key”.


The input to the function/method consists of an argument locking key, an integer

representing the locking key.


Return an integer representing the “unlocking key”.



A possible answer exists for every input

Question 5

highest most character of the word

Example the shift vakues in 'yum feed will be


feed d->0,e->2,f->2

which gives the encryption avm gcd

Here adding the shift with value 1 to letters 'm'gives 'm'+0=m values 1 to 'w' gives

and values 2 to 'y' gives 'y'+2=a and so on

Note that the shift wraps arounding reaching of the file


The input to function/method consists of a string


Return the encrypted string

Question 6

Desigh a way to sort of list of positive integers in the descending order according
to frequency of elements The elements with integers with higher frequency come
before with lower frequency elements with same frequency come in the same order
as they appear the values


The input to the function/methods consists of two arguments

arr a list of poisitive integers

Argu the numbers of elements in the array


Return a list of positive integers sorted according to the functio n of elements

present arr



Arr {1,2,2,3,3,3,4,4,5,5,6,6,6,6,6,7,8,9,10}

Question 7

A sequence of paraenteses is called balanced if it consists entirely of pairs

ofnopening/closing paranteses, which well nested. For example,
sequences”(())()”.”()” and “(()(()))” are balanced, white “(() and “(()))(“ are not.

Write a function to determine if a given string constains balanced sequence of

pareneses. The input to the function balancedParentheses is a string str

For example, if the input sequence is “(()(()))”, the expected output is 4.