Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 92

Computer Fundamentals

and
Coding
Computer Fundamentals

What will be the output of the following pseudocode statements?

(Note: Assume that when two data types are processed through an operator, the answer
maintains the same data type as that of the input. Also, all data types have enough range to
accommodate any number. If two different data types are operated upon, the result assumes the
data type that is more expressive.)

integer a = 456, b, c, d = 10
b = a / d
c = a - b
print c
A. 410 C. 411.4

B. 410.4 D. 411
Computer Fundamentals

What is the output of the program given below?

Integer i = 0, j
while(i < 2)
{
j = 0
while(j <= 3 * i)
{
print j
print blank space
j =j +3
}
print end-of-line //takes the cursor to the next line
i =i +1
}
0 036
A. C.
03 0369
03 036
B. 036 D. 0369
0 3 6 9 12
Computer Fundamentals

Assume the following precedence (high to low). Operators in the same row have the same
precedence.
(.)
*/
-
AND
OR

The precedence is from left to right in the expression for the operators with equal precedence.
Which statement is true about the output of the code statements given below?

integer a = 40, b = 35, c = 20, d = 10


print a * b / c - d
print a * b / (c - d)
A. The outputs differ by 80. C. The outputs differ by 50.

B. The outputs are the same. D. The outputs differ by 160.


Computer Fundamentals

What is the output of the pseudocode statements given below?

(Note: Assume that when two data types are processed through an operator, the answer
maintains the same data type as that of the input. Also, all data types have enough range to
accommodate any number. If two different data types are operated upon, the result assumes the
data type that is more expressive.)

integer a = 984, b = 10
//float is a data type to store real numbers.
float c
c=a/ b
print c
A. 984 C. 98

B. 98.4 D. Error
Computer Fundamentals

What does the following function do?

function operation(int a, int b)


{
if(a > b)
{
return operation(b, a)
}
else
{
return a;
}
}
A. Always returns the first parameter C. Returns the max of (a, b)

B. Returns the min of (a, b) D. Loops forever


Computer Fundamentals

The function given below takes a number "n" as the input and calculates the sum of first "n"
natural numbers. Which statement should be inserted in place of "??" to get the required output?

function sum(n)
{
if(??)
return 1
else
return (n + sum(n - 1))
end
}
A. n equals 1 C. n >= 1

B. n equals 2 D. n>1
Computer Fundamentals

The program to print the sum of all cubes that lie between 0 and 100 is given below. Does this
program have an error? If yes, which statement should be modified to correct the program?

integer i = 0, a // statement 1
integer sum = 0:
a = (i * i * i)
while(i < 100) //statement 2
{
sum = sum + a //statement 3
i =i +1
a = (i * i * i) //statement 4
}
print sum
A. statement 1 C. statement 3

B. statement 2 D. statement 4
E. No Error
Computer Fundamentals

How many times will "Hello" be printed if m < n and exactly one of (m, n) is even

for i= m to n increment 2
print ("Hello!")

(n - m + 1) / 2 1 + (n - m) / 2 if m is even, (n - m + 1) / 2 if m
A. C.
is odd
1 + (n - m) / 2 1 + (n - m) / 2 if m is odd, (n - m + 1) / 2 if m
B. D.
is even
Computer Fundamentals

What will be returned if f(a, b) is called in the following functions?

function g(int n)
{
if(n > 0) return 1;
else return -1;
}

function f(int a, int b)


{
if(a > b) return g(a -
b); if(a < b) return g(b -
a); return 0;
}
A. 1 if a > b, -1 if a < b, 0 otherwise C. 0 if a equals b, +1 otherwise

B. Always +1 D. -1 if a > b, 1 if a < b, 0 otherwise


Computer Fundamentals

A developer writes the program given below to print the sum of the squares of the first five whole
numbers (0...4). Is the program correct? If not, which statement should be modified to correct the
program?

integer i = 0 // Statement 1
integer sum = 0 // Statement 2
while (i < 5) // Statement 3
{
sum = i * i // Statement 4
i = i + 1 // Statement 5
}
print sum // statement 6
A. No error, the program is correct C. Statement 4

B. Statement 1 D. Statement 6
Computer Fundamentals

integer a
pointer c, d
a = 30
c = &a
d= c
a = a + 10
print *c

This code is used with the following meaning:

"pointer" is a data type that contains memory address (or pointers)


Statement "a = *b" puts the value at the memory address referenced by b into a
Statement "a = &b" puts the memory address of b into a
Statement "*b= a" puts the value a at the memory address referenced by b

What will be the output if the compiler saves the first integer at the memory location 4165 and the rest
at the consecutive memory spaces in order of declaration? (Note: The integer is one byte long.)
A. 30 C. 40

B. 4165 D. 4166
Computer Fundamentals

Two programmers, X and Y, are asked to write a code to evaluate the following expression:
a = b + c / (a - b) + (a - b)^2

X writes the following code statements (Code A):


print (a - b) + c / (a - b) + ( a - b) * (a - b)

Y writes the following code statements (Code B):


d = (a - b)
print d + c / d + d * d

Which statement is TRUE if the time taken to load a value in a variable for addition, multiplication or
division between two operands is the same?
Code A uses lesser memory and is slower Code A uses more memory and is faster than
A. C.
than Code B. Code B.
Code A uses lesser memory and is faster Code A uses more memory and is slower
B. D.
than Code B. than Code B.
Computer Fundamentals

Which sorting algorithm yields approximately the same worst case and average-case running time
behavior in O(n logn)?
A. Bubble sort and Selection sort C. Quick sort and Radix sort

B. Heap sort and Merge sort D. Tree sort and Median-of-3 Quick sort
Computer Fundamentals

Identify the range in which a 10-bit Integer lies.

A. 0 to 1000 C. 0 to 1025

B. 0 to 1024 D. 0 to 1023
Computer Fundamentals

A data type is stored as a 6-bit signed integer. Which of the given options cannot be represented by this
data type?
A. -12 C. 32

B. 0 D. 18
Computer Fundamentals

What will be the output of the following pseudocode for p = 2, q = 2?

Integer funn(Integer p, Integer q)


if(p & q > 0)
return funn(q - 2, p)
Else
return 1
End if
return 1
End function funn()
A. 2 C. 0

B. 10 D. 1
Computer Fundamentals

Which expression gives the maximum number of nodes at level "I" of a binary tree? (Note: The root is
at level 1.)
A. 2^(I-1) C. 2^I

B. 3^(I-1) D. 2^I - 1
Computer Fundamentals

A programmer writes a program to find an element in the array A[5] with the elements: 8 30 40 45 70.
The program is run to find a number "X", that is found in the first iteration of binary search. What is the
value of "X"?
A. 40 C. 70

B. 8 D. 30
Computer Fundamentals

A function in the base class is redefined in the inherited class. What is the term used to describe this
situation?
A. Inheritance C. Overloading

B. Overriding D. Encapsulation
Computer Fundamentals

How can a call to an overloaded function be ambiguous?


The name of the function might have been There might be two or more functions with
A. C.
misspelled equally appropriate signatures
There might be two or more functions with None of the above
B. D.
the same name
Computer Fundamentals

Which of the given sorting procedures is the slowest for any given array?

A. Quick sort C. Merge sort

B. Heap sort D. Bubble sort


Computer Fundamentals

Codes A and B have complexities theta(n^3) and omega(n^3), respectively. A sufficiently large problem
with size "K" needs to be solved. Which of the two codes should be used?
Code A Any of the two codes can be used since both
A. C.
have the same complexity
B. Code B D. None of the above
Computer Fundamentals

What can be inherited by a derived class from a base class?

A. Data members C. Constructors and destructors

B. Member functions D. Data members and member functions


Computer Fundamentals

A programmer mistakenly writes "gor" Instead of the keyword "for" used in loops, while writing a
program in C++ What will this result in?
The codes would not compile. The code may work for some inputs and not
A. C.
for the others.
The code would give an error while The code would not create any problem.
B. D.
execution.
Computer Fundamentals

For which of the given options is the stack implementation useful?

A. Radix search C. Recursion

B. Breadth first search D. None of the above


Computer Fundamentals

What best describes the space complexity of a program?


Amount of hard disk space required to Amount of memory required for the
A. C.
store the program program to run
Amount of hard disk space required to Amount of memory required for the
B. D.
compile the program program to compile
Computer Fundamentals

A librarian has to rearrange the library books on a shelf in a proper order at the end of each day. Which
sorting technique should be the librarian's ideal choice??
A. Bubble sort C. Selection sort

B. Insertion sort D. Heap sort


Computer Fundamentals

Which members of a class cannot be inherited?

A. Public C. Private and Protected

B. Private D. Protected
Computer Fundamentals

A programmer writes an efficient program to sum two square diagonal matrices (matrices with
elements only on the diagonal positions). The size of each matrix is n x n. What is the time complexity
of the algorithm?
A. O(n^2) C. O(n * log (n))

B. O(n) D. None of the above


Computer Fundamentals

What will be the output of the following pseudocode?

Integer a, b, c
Set a = 3, b = 4, c = 5
b=b+a-1
if(c > b OR b < a)
if(c > a)
a=2
End if
b=b+1
End if
Print a + b + c
A. 14 C. 18

B. 9 D. 21
Computer Fundamentals

What will be the most efficient approach to find the largest number in a list of twenty numbers?
Use bubble sort to sort the list in a Implement one iteration of selection sort for
A. descending order and then print the first C. descending order and print the first number
number of the series in the series
Use selection sort to sort the list in a None of the above
B. descending order and then print the first D.
number of the series
Computer Fundamentals

A stack is implemented as a linear array A[0...N-1]. A programmer writes the function given below to
pop out an element from the stack.

function POP(top, N)
{
if(X)
{
top = top - 1
}
else
{
print "Underflow"
}
return top
}

What should substitute the condition "X"?


A. top < N-1 C. top > 1

B. top < N D. top >= 0


Computer Fundamentals

A sorting algorithm traverses through a list, comparing adjacent elements and switching them under
certain conditions. What is this sorting algorithm called?
A. Insertion sort C. Quick sort

B. Heap sort D. Bubble sort


Computer Fundamentals

What will be the output of the following pseudocode?

Integer m
Set m = 11
Integer a[4] = {10, 11, 1, 12}
a[1] = a[1] - a[3]
a[2] = a[2] + a[2]
a[3] = 1 + a[3]
m = a[3]
if (m > a[2])
m=m- 1
Else
m=m+1
End if
Print m
A. 18 C. 12

B. 22 D. 7
Computer Fundamentals

Which of the given statements refers to data encapsulation in object oriented programming?

The data of an object is encapsulated in its The data and operations for an object are
A. C.
class defined and fixed.
B. The data is hidden for an object D. A class can have multiple objects
Computer Fundamentals

Consider an array on which bubble sort is used. To which of the given elements will the bubble sort
compare the element A[x] with, in a single iteration?
A. All of the above C. A[X+2x]

B. A[X+1] D. A[X+2]
Computer Fundamentals

A class contains two integers as private members. Two member functions (public) defined in it - one to
add the two integers and another to subtract the two integers. A programmer wants to add a new
functionality to enables multiplication of the two numbers. Which of the given options should be
adopted to do this?
Define private member functions to return Define a third private member function
the value of both the integers and then that multiplies the two numbers.
multiply them in the code. By returning the
A. C.
values any operation can be performed on
them in the future, giving extensibility to the
code.
Define public member functions to return Define a third public member function that
value of both the integers and then multiply multiplies the two numbers.
B. them in the code. By returning the values D.
any operation can be performed on them in
the future, giving extensibility to the code.
Computer Fundamentals

A programmer writes a sorting algorithm that takes different amount of time to sort two different lists
of equal size. What is the possible difference between the two lists?
All numbers in one list are more than 100 One list contains 0 as an element while the
A. C.
while in the other are less than 100. other does not.
The ordering of numbers with respect to the One list has all negative numbers while the
B. magnitude in the two lists has different D. other has all positive numbers.
properties.
Computer Fundamentals

The function given below takes an even integer "n" as the input and calculates the sum of first "n"
even natural numbers. The function is called by the statement "sum(30)". How many times will the
function "sum" be called to compute the sum?

function sum(n)
{
if (n equals 2)
return 2
else
return (n * sum(n - 2))
end
}
A. 15 C. 1

B. 16 D. 30
Computer Fundamentals

Why is an algorithm designer concerned primarily about the run time and not the compile time while
calculating time complexity of an algorithm?
Run time is always more than compile time. Compile time is always more than run
A. C.
time.
A program needs to be compiled once but Compile time is a function of run time.
B. D.
can be run several times.
Computer Fundamentals

What will happen if some indentation is made in some statement of a code written in C++?

A. Better readability of the code C. Correction of errors in the code

B. Lower memory requirement for the code D. Faster execution of the code
Computer Fundamentals

A developer writes the program given below to print the sum of the squares of the first five whole
numbers (0...4) is the program correct? If not, which statement should be modified to correct the
program ?

integer i = 0 // Statement 1
integer sum = 0 // Statement 2
while (i < 5) // Statement 3
{
sum = i * i // Statement 4
i = i * i // Statement 5
}
print sum // Statement 6
A. No error, the program is correct C. Statement 6

B. Statement 4 D. Statement 1
Computer Fundamentals

How many nodes does a full binary tree with "n" leaves contain?

A. 2n-1 nodes C. 2n + 1 nodes

B. log2n nodes D. 2n nodes


Computer Fundamentals

How are protected members of a base class accessed in the derived class when inherited privately in C+
+?
A. Publicly C. Not inherited

B. Privately D. Protectedly
Computer Fundamentals

Which of the given statements is TRUE about a breadth first search?

None of the above Beginning from a node all the adjacent


A. C.
nodes are traversed first search
Beginning from a node the nodes are Beginning from a node each adjacent node
B. traversed in cyclic order D. is fully explored before traversing the next
adjacent node
Computer Fundamentals

A programmer writes the given program to print the following pattern on the screen
1
12
123
will this program function property? If not, which statement should

integer i = 1 // Statement 1
while (i <= 3)
{
int j // Statement 2
while (j <= i) // Statement 3
{
print j
print blank space
j = j + 1 // Statement 4
}
print end-of-line // takes the cursor to next
line i = i + 1
}

A. Statement 1 C. Statement 2

B. Statement 4 D. Statement 3
Computer Fundamentals

Code A contains a set of eight lines that occur 10 times in different points of the program. This code is
passed to a programmer who puts the set of eight lines in a function definition and calls them at the
ten points in the program. Assume this new code to be B. Which code will run faster using an
interpreter?
A. Code B C. None of the above

Code A Both the codes would run at the same


B. D.
speed
Computer Fundamentals

In which of the given methods is sorting NOT possible?

A. Insertion C. Selection

B. Deletion D. Exchange
Computer Fundamentals

A Programmer tries to debug a code of 10,000 lines. It is known that there is a logical error in the first
25 lines of the code. what is an efficient way to debug the code?
Use an interpreter on the first 25 lines of Compile the entire code and check it line
A. C.
code by line
Compile the entire code and run it None of the above can be used to debug
B. D.
the code
Computer Fundamentals

A sorting mechanism uses the binary tree concept such that any number in the tree is larger than all
the numbers in the sub-tree below it. What is this method called?
A. Heap sort C. Quick sort

B. Selection sort D. Insertion sort


Computer Fundamentals

In an implementation a-linked list, each node contains data and address, what can the address field
possibly contain?
A. Address of the last node C. Its own address

B. Address of the first node D. Address of the next node in sequence


Computer Fundamentals

A programmer prepares a questionnaire with "true or false "type of questions. He wants to define a
data type that stores the responses of the candidates for the questions. Which is the most suited data
type for this purpose?
A. Boolean C. Character

B. Float D. Integer
Computer Fundamentals

Identify the lowest level format to which the computer converts a higher language program before
execution?
A. System Language C. Machine Code

B. English code D. Assembly Language


Computer Fundamentals

Which of the given statements is TRUE about a variable?

A variable cannot be used in the function it is A variable cannot be used after it is


A. C.
declared in declared
A variable be used before it is declared A variable can always be used after
B. D.
declared
Computer Fundamentals

A programmer is making a database of animals in a zoo along with their properties. The possible
animals are Dog, lion and zebra. Each one has attribute as Herbivorous, color and Nocturnal. The
programmer uses the object oriented programming paradigm for this. How will the system be
conceptualized?
class: Animals; object: Herbivorous, color None of these
A. and Nocturnal; data members: dog, lion and C.
zebra
classes: dog, lion and zebra; object: Animals; class Animals; object: dog lion and zebra;
B. data members: Herbivorous, color and D. data members: Herbivorous,
Nocturnal. color and Nocturnal.
Computer Fundamentals

A programmer wants the program given below to print the largest number out of three numbers entered by the
user. What should be used in place of "??" Statement1 in the code ?

int number1, number 2, number3,


temp; input number1, number2,
number3;
if (number1 > number2)
temp = number1
else
temp = number2
end if
if (??) // Statement 1
temp = number3
end if
print
temp
A. number3 > temp C. number3 > number1

B. number3 > number2 D. number3 < temp


Computer Fundamentals

X and Y are asked to write a program to sum the rows of a 2x2 matrix stored in an array A.
X writes the code (Code A) as follows:
for n = 0 to 1
sumRow1[n] = A[n][0] + A[n][1]
End

Y writes the code (Code B) as follows:


sum Row 1[0] = A[0][0] + A[0][1]
sum Row1[1] = A[1][0] + A[1][1]

Which of the following statements is correct about these codes if no loop unrolling is done by the
compiler?
A. Code B would execute faster than Code A. C. Code B is logically incorrect

B. Code A is logically incorrect D. Code A would execute faster than Code B.


Computer Fundamentals

Refer to the given pseudocode. The code is similar to that in C++ and self- explanatory An accessible member function or data
member for an object are accessed by the statement objectname, functionname or objectname. datamembername respectively.

What can be inferred from this code?

Class rocket
{
Private:
integer height, weight
public: //statement 1
function input(int a, int b)
{
height = a;
weight = b;
}
}
function main()
{
rocket rocket1, rocket2
}
rocket is a class with rocket1 and rocket2 as its attributes. rocket is a class with rocket1, rocket2,height and
A. C.
height and weight are objects of the class rocket. weight as its attributes
rocket is a class with rocket 1 and rocket2 as its objects. rocket is a class with rocket1, rocket2, height, weight as
B. D.
height and weight are attributes of a rocket. its objects.
Computer Fundamentals

Which of the following algorithm design technique is used in the quick sort algorithm?

A. Dynamic programming C. Divide and conquer

B. Greedy method D. Backtracking


Computer Fundamentals

What will be the output of the following pseudocode?

String str1 = "mMaa", str2 = "Oaaa"


Print lower(str1) + lower(str2) + upper(str1) + "aaa"

Note: upper(string) converts all the letters of the string to upper case. Ex-upper("OkaY") would return
"OKAY"
lower(string) converts all the letters of the string to lower case. Ex-lower("OkaY") would return "okay"]
A. mmaaoaAAaaa C. mmaaoaaaMMAAaaa

B. mmaoaaaMMAAaaa D. mmaaoaMMAAaaa
Computer Fundamentals

What will be the output of the following pseudocode?

Integer a, b, c
Set a = 15, b = 71, c = 4
if(a > c + 100)
if (b > c)
c= b
b = a
a=c
End if
b= a
Else
a=c+ b
End if
Print a + b + c
A. 150 C. 147

B. 153 D. 158
Computer Fundamentals

What will be the output of the following pseudocode?

character a[20], b[20]


set a[20] = "I am the best"
Integer k, j
set k = 0
while (a[k] NOT EQUALS null character)
b[k] = a[k]
k=k+1
End while
for (each j from 0 to 12)
print b[j]
end for
it will copy the string from character array a to b It will print the reverse string of given character
A. C.
array
B. It will print the last word of given character array D. 0
Computer Fundamentals

What will be the output of the following pseudocode?

character a[20], b[20]


set a[20] = "I am the best"
Integer k, j
set k = 0
while (a[k] NOT EQUALS null character)
b[k] = a[k]
k=k+1
End while
for (each j from 0 to 12)
print b[j]
end for
A. it will copy the string from character array a to b C. It will print the reverse string of given character array

B. It will print the last word of given character array D. 0


Computer Fundamentals

What will be the output of the following pseudocode?

Integer p, q, r
Set p = 1, q = 3
for(each r from 5 to 6)
if(p > r)
p=r
End if
if(p + 2 > r - 5)
q = p + 10
else
Continue
End if
End for
Print p + q

Note:
Continue: When a continue statement is encountered inside a loop, control jumps to the beginning of the loop for
next iteration, skipping the execution of statements inside the body of the loop for the current iteration.
A. 12 C. 21
B. 14 D. 8
Computer Fundamentals

What will be the output of the following pseudocode?

Integer m
Set m = 1
Integer a[4] = {1, 4, 1, 2}
if(a[1] mod 3)
a[2] = a[1] & 2
End if
m = a[1] & a[2]
Print m

Note:
&: bitwise AND- The bitwise AND operator (&) compares each bit of the first operand to the
corresponding bit of the second operand. If both bits are 1, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0.
A. 0 C. 3
B. -6 D. 10
Computer Fundamentals

What will be the output of the following pseudocode?


Integer a, b, c
Set a = 1, b = 1
if(a - b)
for(each c from 1 to 3)
a=a+1
if(a)
Jump out of the loop
End if
End for
Else
for(each c from 1 to 4)
a=a+1
End for
End if
a=a+b
Print b + a
A. 8 C. 7
B. 9 D. 2
Computer Fundamentals

What will be the output of the following pseudocode?

Integer a, b
for(each a from 1 to 2)
b = 17
print b + a – a * a
end for
print a + 1

A. 17 15 4 C. 17 4 15
B. 123 D. 17 17 16
Coding
Clockwise Rotations Input Format
Charlie has a magic mirror. The mirror shows Two lines of input. Each line contains strings.
right-rotated versions of a given word. To generate Output Format
different right rotations of a word, write the word
Single integer
in a circle in clockwise order, then start reading
from any given character in clockwise order till Sample Input 1
you have covered all the characters. abcd
For example: In the word "sample", if we start dcba
with 'p', we get the right rotated word as Sample Output 1
"plesam". There are six such right rotations of -1
"sample" including self.
def isSameReflection(inStr1, inStr2):
The inputs to the function isSameReflection # Write Your Code Here
consists of two strings, word1 and word2. The
# Driver Code inStr1 = input() inStr2 = i
function returns 1, if word1 and word2 are right print(isSameReflection(inStr1,inStr2))
rotations of the same word and -1 if not. Both
word1 and word2 will strictly contain characters
between 'a'-'z' (lowercase letters).
Coding
Unique Repeating Digits def
InputfindFrequncy(S):
Format
# input
The Write YourofCode
consists integerHere
- data, representing
A company is transmitting data to another
server. The data is in the form of numbers. To the data to be transmitted.
# Driver Code
secure the data during transmission, they plan SOutput Format
= input()
to obtain a security key that will be sent along Print an integer representing the security key for
print(int(findFrequncy(S)))
with the data. The security key is identified as the given data.
the count of the unique repeating digits in the Sample Input 1
data.
578378923
Sample Output 1
Write an algorithm to find the security key for
the data. 3
Coding
Auto-Learning Dictionary Input Format
The input consists string-textInput, representing
A company called Dictionary is launching a new
the text that is given as an input to the
dictionary application for mobile users. Initially, the application by the user
dictionary will not have any words. Instead it will be Output Format
an auto-learning application that will learn according
Print space separate strings in the
to user's given text. When a user types text, the lexicographically sorted order representing
application auto detect the words that appear more the number of repeated words detected input
than once. The application then stores these words in text and if no words is repeated print ''NA''
the dictionary and uses them as suggestions in the Sample Input 1
future typing sessions. abc bcd cde abc bcd
Sample Output 1
Write an algorithm to identify which word will be abc bcd
saved in the dictionary. def wordsFreq(text):
Note: A word is alphanumeric sequence of a character # Write Your Code Here
having no white space and there is no punctuations in # Driver Code
the input text. Text input is case sensitive ( i.e. 'cat' and text = input()
Print(wordsFreq(text))
'CAT' are considered as different words not same ).
Coding
Prime Sum Input Format
Jackson, a math research student, is developing an application on The first line of the input consists of
prime numbers. For the given two integers on the display of the an integer - rangeLeft, representing
application, the user has to the identify the largest and smallest the minimum boundary value of the
prime numbers within the given range (including the given values). given range. The second line
Afterwards, the application will sum up the largest and smallest consists of an integer-rangeRight,
prime numbers. Print -1 if there is no prime number in given range. representing the maximum
boundary value of the given range.
Jackson has to write an algorithm to find the sum of the largest and
smallest prime numbers for the given range.
Output Format
Single integer
def primeSum(rangeLeft, rangeRight):
# Write Your Code Here Sample Input 1
67
# Driver Code 140
rangeLeft = int(input())
rangeRight = Sample Output 1
int(input()) 206
Coding
Encrypted Number Input Format
The company digital Secure data transfer solutions The first line of input consists of an integer data
representing the number. The second line
provide the data encryption and data sharing services.
consists of an integer , representing the key(K).
Their process uses a key K for encryption when
Output Format
transmitting a number. To encrypt a number, each
digit in the number is replaced by the Kth digit after it Print an integer representing the encrypted
number.
in the number. The series of digits is considered in a
Sample Input 1
cyclic fashion for the last K digits .
25143
3
Write an algorithm to find the encrypted number.
Sample Output 1
43251
Constraint on data:
def encryptData(num, K):
0 < data <=109
.

\\ Write Your Code Here

\\ Driver Code num


= int(input()) K =
int(input())
print(encryptData(num, K))
Coding
Negative Temperature Input Format

A cold storage company has N storage units for various The first line of the input an Integer
products. The company has received N orders that must be numOfProducts, representing the
preserved at respective N temperatures inside the storage units. number of products (N). The second
The company manager wishes to identify which products must line consists of N space separated
be preserved at negative temperatures. integers - tempreature0, tempreature1,
…. ., tempreatureN-1, representing the
Write an algorithm to help the manager find the number of temperatures at which the product
products that have negative temperature storage requirements. must be preserved in the storage units.
Output Format

def negativeTempCount(Temp, Print an integer representing the


N): # Write Your Code Here number of products that must be
preserved at negative temperatures.
Sample Input 1
5
# Driver Code 10 -12 43 -13 80
N = int(input())
Temp = list(map(int, input().split())) Sample Output 1
print(negativeTempCount(Temp, N)) 2
Coding
Order Count Input Format

A company manufactures different types of software products. The first line of the input consists of an
They deliver their products to their N clients. Whenever the integer- numOfClients, representing
company fulfills the complete order of a clients, the orderID the number of clients (N). The second
generated is the concatenation of the number of products line consists of N space-separated
delivered for every committed product type, the head of the integers orderID0, orderID1,. ,
sales team wishes to find the client wise data for the total orderIDN-1,
number of products of any type delivered to every client. representing the order IDs of the orders
Write an algorithm for the head of the sales team to calculate delivered the clients.
the total number of products of any type delivered to the Output Format
respective clients. Print N space-separated integers,
representing the client wise data for the
def totalProducts(Orders): total number of products of any type
delivered to each of the respective clients.
# Write Your Code Here
Sample Input 1
# Driver Code
N = int(input()) 4
Orders = list(map(int, input().split())) 43 345 20 987
print(*totalProducts(Orders)) Sample Output 1
Coding
Day Max Profit Input Format

A company has a sales record of n products for The first line of input consists of two space-separated
integers - day and products, representing the days (M)
m days. the company wishes to know the and the products in the sales record (N), respectively. The
maximum revenue received from a given next M lines consist of N space-separated integers -
product of the n products each day. Write an saleRecord, representing the grid of the sales revenue
algorithm to find the highest revenue received (can be positive or negative) received from each product
each day. each day.
Output Format
def dayMaxProfit(mat):
# Write Your Code Print M space-separated integers representing the
Here maximum revenue received each day.

Sample Input 1
#Driver Code 34
M, N = map(int, input().split()) 100 198 333 323
mat = [] 122 232 221 111
for i in range(M): 223 565 245 764
row = list(map(int,input().split()))
mat.append(row) Sample Output 1
333 232 764
Coding
Discounted Product Input Format
An e-commerce company is planning to give a special The first line of the input consists of two space-separated
discount on all its products to its customers for the integers – numOfProducts and disAmount. Order N
representing the current status of the stock for the orders of
holiday. The company possesses data on its stock of N
the respective product types.
product types. The data for each product type
represents the count of customers who have ordered the Output Format
given product. If the data K is positive, then it shows that Print an integer representing the number of products out of N
the product has been ordered by K customers and is in for which the discount will be distributed.
stock. If the data K is negative, then it shows that it has
Sample Input 1
been ordered by K customers but is not in stock. The
company will fulfil the order directly if the ordered 7 18
product is in stock. If it is not in stock, then the company 9 -3 8 -7 -8 18 10
will fulfil the order after they replenish the stock from Sample Output 1
the warehouse. They are planning to offer a discount 2
amount A for each product. The discount value will be
distributed to the customers who have purchased that def disProdcut(orders, dis, N):
selected product. The discount will be distributed only if # Write Your Code Here
the decided amount A can be divided by the number of
# Driver Code
orders for a particular product. Write an algorithm for N, dis = map(int, input().split())
the sales team to find the number of products gets the orders = list(map(int, input().split()))
discount. print(disProdcut(orders,dis, N))
Coding
Cab Distance
A company wishes to provide cab service for their N employees.
The employees have IDs ranging from 0 to N-1. The company
has calculated the total distance from an employee's residence
to the company, considering the path to be followed by the cab
is a straight path. The distance of the company from itself is 0.
The distance for the employees who live to the left side of the
company is represented with a negative sign. The distance for
the employees who live to the right side of the company is
represented with a positive sign. The cab will be allotted a
range of distance. The company wishes to find the distance for
the employees who live within the particular distance range.
Write an algorithm to print the distance of the employees who
live within the distance range.
def distance(dist, start, end):
# Write Your Code Here

# Driver Code
num = int(input())
dist = list(map(int, input().split()))
start = int(input())
end = int(input())
print(*distance(dist, start, end))
Input Format
The first line of the input consists of an integer- num,
representing the size of the list(N). The second line consists of N
space- separated integers representing the distances of the
employees from the company. The third line consists of an
integer- start, representing the starting value of the range. The
last line consists of an integer- end, representing the stop value
of range.

Output Format
Print space-separated integers representing the distance for
employees whose distance lies within the given range else return
-1.
Sample Input 1
5
10 -4 -5 12 16
-5
12

Sample Output 1
10 -4 -5 12
Coding
Lucky Stock Price Input Format
A stock trader who trades in N selected stocks. The first line of the input consists of integer –
numOfStocks, representing the number of selected
He has calculated the relative stock price
stocks (N). The second line consists of N space-
changes in the N stocks from the previous day separated integers – stock1, stock2, ……, stock N
stock prices. Now, his lucky number is K, so he representing the relative stock prices of the selected
wishes to invest in the particular stock that stocks. The third line of input consists of integer
value k, for which he wishes to find the stock price.
has Kth smallest relative stock value. Write an
algorithm for Andrew to find the Kth smallest Output Format
stock price out of the selected N stocks. Print an integer representing the Kth smallest stock
price of selected N stocks.
def kthSmallestStock(price, N,
Sample Input 1
K): # Write Your Code Here
5
# Driver Code 10 5 7 88 19
N = int(input()) 3
price = list(map(int,
input().split())) K = int(input()) Sample Output 1
print(kthSmallestStock(price, N, K)) 10
Coding
Feel Good
The apparel company 'FeelGood' has collected a
list of the sales values of the N highest selling
brands of products during the festive season.
Each brand is identified by a unique ID
numbered 0 - (N-1) in the list. From this list the
company wishes to determine the Kth largest
sales value for a given day.
Write an algorithm to help the company
determine the sales value of the Kth largest
selling product.
def kthLargestStock(price, N, K):
# Write Your Code Here

# Driver Code
N = map(int,(input().split()))
price = list(map(int, input().split()))
K = int(input())
print(kthLargestStock(price, N, K))
Input Format
The first line of input consists of two integers
numBrands and largest Sale where the first integer
represents the total number of brands selected by the
company (N) and the second integer represents the
Kth value. The next line consists of N space separated
integers - salesValue[0], salesValue[1], … salesValue[N-
1] representing the sales value of the N brands.
Output Format
Print an integer representing the Kth largest sales
value in the list for the given day.
Sample Input 1
5
45 32 67 21 12
3
Sample Output 1
32
Coding
Balloons Sum Input Format
The games development company "FunGames" has The input consists of an integer -
developed a balloon shooter game. The balloons are numBallons representing the total
arranged in a linear sequence and each balloon has number of balloons shot by the player
a number associated with it. The numbers on the (k).
balloons are in fibonacci series. In the game the
player shoots 'k' balloons. The player's score is the Output Format
sum of numbers on the 'k' balloons. Write an Print an integer value representing the
algorithm to generate the player's score. player's score. If no balloons are shot
Constraint then print 0.
6
2 <= numBalloons <= 10 Sample Input 1
def playerScore(numBallons): 7
# Write Your Code Here Sample Output 1
# Driver Code 20
numBallons = int(input())
print(playerScore(numBallons))
Coding
Lucky Lottery Input Format
The "LuckyLottery" has a list of N lottery ticket The first line of the input consists of an
codes. The ticket code is a numeric value. The integer - size, representing the size of the
lottery has to shortlist the runner up prize winner. list (N). The second line consists of N
0
The shortlisting strategy involves selecting the code space-separated integers - ticket ,
1
whose frequency in the list is equal to its value. If ticket ,..ticketN-1
there are multiple codes whose frequency in the list representing the ticket codes.
is equal to its value, select the one which has the Output Format
largest value. Write an algorithm to select the Print an integer representing the code of
shortlisted ticket code. the shortlisted ticket. If no code exists,
def luckyLottery(arr, N): output-1.
# Write Your Code Here Sample Input 1
8
# Driver Code 27234323
N = int(input()) Sample Output 1
arr = list(map(int, input().split()))
print(luckyLottery(arr, N)) 3
Coding
Pair Wise Special Character Input Format
A company has to tag its products. Each product The input consists of a string - productType,
has an associated product type which is used to tag representing the product type of the product.
the products. Product type is a sequence of lower- Output Format
case letters from the English alphabet. The
company want to have an algorithm for their Print a string representing the tag for the given
system which takes the product type and outputs product.
the tag. To generate the tag, pairs of adjacent Sample Input 1
characters are formed from the start of the product electronics
type. From each pair the lexicographically smallest
character will be removed. If a character will be Sample Output 1
left unpaired then that character will be taken as it letois
is in the tag. Write an algorithm for the company def pairwiseSpecial(reg): # Write Your Co
system to find the tag for the given
product. Note: # Driver Code reg = input()
print(pairwiseSpecial(reg))
The product type consists of lower-case letters
from the English alphabet ('a' - 'z') If both
characters in a pair are the same, then any
character in the pair can be removed.
Coding
Brain Game Input Format
A game developing company has developed a math The first line of the input consists of an integer-
game for kids called 'Brain Fun'. The game is for size, representing the size of the list (N). The
smartphone users and the player is given a list of N second line of the input consists of an integer-
positive numbers and a random number K. The player value, representing the numeric value by which
needs to divide all the numbers in the list with the the numbers in the list will be divided (K). The
last line consists of N space-separated integers -
number K and then needs to add all the quotients
num0, num1, ..., numN-1, representing the numbers
received in each division. The sum of all the quotients
in the list.
is the score of the player.
Write an algorithm to generate the score of the player. Output Format
Print an integer representing the score of the
def brainGame(arr, N, K): player.
# Write Your Code Here
Sample Input 1
# Driver Code 5
N = int(input()) 4
K = int(input()) 25 26 54 81 48
arr = list(map(int, input().split()))
Sample Output 1
print(brainGame(arr, N, K))
57
Coding
Perfect Cube Price
A customer buys N number of products from a shop and
each product has a different price. During the holiday
season the shop owner decides to introduce a special
offer. He wishes to distribute gift hampers to customers
who purchase products whose total price is a perfect
cube. If customers don't meet this requirement, the
owner will allow them to buy a few more products in
order to make the total price a perfect cube. Write an
algorithm to print "Yes" if the customer will receive a gift
hamper, else print an integer representing the price of
the product the customer should buy in order to receive a
gift hamper.
def perfectCube(arr, N) -> None:
# Write Your Code Here
# Driver Code
N = int(input())
arr = list(map(int, input().split()))
perfectCube(arr, N)
Input Format
The first line of the input consists of an integer
- numProduct, representing the number of
products(N). The next line consists of N space-
separated integers - price[0], price[1], …
price[N-1], representing the price for all the
products.

Output Format
Print "Yes" if the customer will receive a gift
hamper, else print an integer representing the
price of the product the customer should buy
in order to receive a gift hamper.
Sample Input 1
6
60 7 8 10 250 730
Sample Output 1
266
Coding
Storage Cell
An e-commerce company's warehouse has N number of storage
cells. Each cell is uniquely recognized by a numeric value, known
as the identification number (ID), labeled 0 to N-1. These
storage cells store items where each item is uniquely identified
by their item ID. These items are stored sequentially in the
storage cell and one item can be stored in one cell only. The
warehouse system has all the data related to these cells. The
company has a new item X in stock for storage where X
represents the item ID. The company wishes to know whether
item X is available in the warehouse or not. If available, the
system must return the ID of the cell where this item is stored. If
X is not available, the system must return the ID of the cell
where the item would be stored. Write an algorithm to return
the cell ID for item X
def cellID(stocks,itemID):
#Write Your Code Here

# Driver Code
numCell, itemID = map(int, input().split())
stocks = list(map(int, input().split()))
print(cellID(stocks,itemID))
Input Format
The first line of input consists of two space-
separated integers - num Cells and itemID,
representing the total number of cells in the
warehouse(N) and the new item ID (X) The
second line of input consists of N space-

separated integers- stock1, stock2, stock3 stockN-1,


representing the item IDs of the items present in
these cells.
Output Format
Print space-separated integers representing the
ID of the cell in which item X is present, or the ID
of the cell in which it will be stored.
Sample Input 1
63
2 3 4 5 8 10
Sample Output 1
1
Coding
Transfer Encrypted Code Input Format
A company transfers an encrypted code to one The first line of the input consists of an integer
encrypted Code, representing the encrypted code
of its clients. The code needs to be decrypted
given to the client.
so that it can be used for accessing all the
required information. The code can be Output Format
decrypted by interchanging each consecutive Print an integer representing the decrypted code
digit and once a digit has been interchanged that can be used for accessing the required
then it cannot be used again. If at a certain information.
point there is no digit to be interchanged with, Sample Input 1
then that single digit must be left as it is. 39631
Sample Output 1
Write an algorithm to decrypt the code so that
93361
it can be used to access the required
information. def decryptCode(num):
# Write Your Code Here

# Driver Code
num = int(input())
print(decryptCode(num))
Coding
Calculate Credit Score Input Format

The new bank, "YoursPay", has a list of N The first line of input consists of an integer-
numCustomers, representing the number of banking
customers' bank account balances. The list
customers (N). The second line of input consists of N
consists of both positive and negative
space separated integers - balance0, balance1,.balanceN-1
balances. The positive balance signifies the
representing the customers' bank balances.
current year's customers and the negative
Output Format
balance signifies last year's customers. The
Print an integer representing the credit score.
bank has decided to offer shortlisted
Sample Input 1
customers credit scores to their credit cards.
5
The credit score will be the sum of the two 1 8 -5 7 5
balances from the list with the smallest Sample Output 1
product when multiplied. If the credit score is 3
positive then the credit will be provided to the def creditScore(arr, N):
current year's customer, otherwise it will go to # Write Your Code Here
the last year's customer. Write an algorithm to
# Driver Code
find the credit score.
N =
arr = list(map(int, input().split()))
print(creditScore(arr, N))

You might also like