0% found this document useful (0 votes)
7 views

coding pdfvbb

The document contains a series of 30 multiple-choice questions related to programming concepts, algorithms, and data structures, specifically tailored for an Infosys assessment. Each question presents a code snippet or a problem statement, followed by four answer options. The questions cover various topics including recursion, bit manipulation, array processing, and string manipulation.

Uploaded by

charishma ramya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

coding pdfvbb

The document contains a series of 30 multiple-choice questions related to programming concepts, algorithms, and data structures, specifically tailored for an Infosys assessment. Each question presents a code snippet or a problem statement, followed by four answer options. The questions cover various topics including recursion, bit manipulation, array processing, and string manipulation.

Uploaded by

charishma ramya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Infosys Pseudocode Practice

Questions
30 Multiple Choice Questions with
Solutions
Questions
1. Consider the following recursive function used in an Infosys assessment. What will be the output for input values
x = 4 and y = 3?

calculateSum(Integer x, Integer y)
x=4 & y=3
if(y EQUALS 0)
return 0 return calculatesum(8 , 1)+4
if(y mod 2 EQUALS 0)
return calculateSum(x + x, y/2)
return calculateSum(x + x, y/2) + x x= 8 , y=1
End function return calculate sum(16,0)+8

a. 16
b. 12
c. 8
d. 20

2. In an Infosys coding round, the following function was given. What would be its output for parameters a = 3 and b
= 4? ans = 3+3+

1st iteration:
recursiveCompute(Integer a, Integer b) a = 3 , b=4
if(b EQUALS 1) return 3+rc(3,3)
return a
else
2nd iteration:
return a + recursiveCompute(a, b-1) a=3,b=3
End function 3+rc(3,2)

a. 12 3+ rc(3,1)
b. 9
c. 15
d. 6

3. A candidate was asked to analyze this code snippet in an Infosys interview. What will be the output if x = 5 and y
= 3?

x=5, y=3
processValues(Integer x, Integer y)
Integer result = 0 1st 3%2 = 1 -> res = 0+5 = 5 -> res =5
while(x > 0)
x=4 , y=4
if(y mod 2 EQUALS 1) 4%2 = 0 (false)
result = result + x
x= 3, y=5
x = x - 1
res = 5+3 = 8
y = y + 1
End while
x=2 , y=6
false
return result
End function x =1, y=7
res = 8+1 = 9

a. 9 x=0,y=8
b. 13
c. 10
d. 12

4. During an Infosys online assessment, the following code was presented. What will be printed if initial value of n =
16?

Integer findPattern(Integer n)
if(n <= 1)
16%2=0
return 1
call function(8)
if(n mod 2 EQUALS 0) callfunction(4)
return findPattern(n/2)
callfunction(2)
callfunction(1) -> return 1
else
return findPattern(3*n + 1)
End function

a. 4
b. 1
c. 2
d. 8

5. In an Infosys technical round, candidates were given this code. What's the output for a = 7?
a=7

Integer mysterySequence(Integer a) a=7 -> a=22 , c =1


a=22-> a=11,c=2
Integer count = 0
a=11 -> a=34 , c=3
while(a NOT EQUALS 1) a=34-> a=17,c=4
if(a mod 2 EQUALS 0) a=17-> a=52 ,c=5
a=52-> a=26 , c=6
a = a/2 a=26-> a=13, c=7
else a=13 -> a=40, c=8
a=40 -> a=20,c=9
a = 3*a + 1
a=20-> a=10, c=10
count = count + 1 a=10 -> a=5 , c=11
End while a=5 -> a=16 , c=12
a=16-> a=8,c=13
return count a=8 -> a=4, c=14
End function a=4-> a=2, c=15
a=2 -> a=1 , c=16
a=1 -> end while
a. 16
b. 17
c. 15
d. 14

6. The following bit manipulation code appeared in an Infosys test. What's the output for n = 42?

Integer countBits(Integer n) n=42-> c=0+0 =0 -> c=0,n=21


Integer count = 0 n=21 -> c=0+1 = 1 -> c=1, n = 10
n=10 -> c= 1+0 -> c=1, n=5
while(n > 0) n=5-> c=1+1 =2 , c=2 , n=2
count = count + (n mod 2) n=2 -> c= 2+0 = 2-> c=2, n=1
n=1 -> c=2+1 =3 -> c=3, n=0
n = n/2
n=0 -> end while and print count ->3
End while
return count
End function

a. 3
b. 4
c. 5
d. 6

7. An Infosys interviewer asked about this pattern-generating code. What's printed for n = 4?

*
void printPattern(Integer n) i= 1 , j = 1 to 1 -> *
**
i=2 , j= 1 to 2(1&2) -> **
for i = 1 to n ( 1-4) ***
i=3, j= 1 to 3 -> ***
****
for j = 1 to i i=4 , j= 1 to 4 -> ****
print "*"
End for
print newline
End for
End function
b-> * *
** *
*
*** **
*
***** -> c *** -> d
a. 4 stars in a line **** *
b. 4 stars in a column
c. 10 stars in a triangle
d. 6 stars in a triangle

8. This array manipulation code was part of an Infosys assessment. What's the result for arr = [1,2,3,4,5]?

Integer arrayOperation(Array arr) i=0 -> sum = 0+1 -> sum=1


i=1 -> 1%2!=0 -> skip
Integer sum = 0 i=2-> sum = 1+3 -> 4
for i = 0 to length(arr)-1 i=3 -> skip
i=4 -> sum = 4+5 -> sum=9
if(i mod 2 EQUALS 0)
sum = sum + arr[i]
End for
return sum
End function

a. 15
b. 6
c. 9
d. 12

9. During an Infosys coding test, this function was given. What's returned for str = "INFOSYS"?

Integer analyzeString(String str)


Integer vowels = 0 infosys
for each char in str
if char in ['A','E','I','O','U']
vowels = vowels + 1
End for
return vowels
End function

a. 2 or -> 1or1 -> 1 xor -> same unte-> 0


and -> 1&1 -> 1
0 or 1-> 1 else: 1
b. 3 0&0->0
0&1->0 1 or 0 -> 1
c. 1 0 or 0 -> 0 1-> (1^0 and 0^1)
1&0->0
0 -> (1^1 and 0^0)
d. 4

10. Candidates faced this logical operation code in an Infosys exam. What's the output for a = 15, b = 12?

Integer computeLogic(Integer a, Integer b)


return (a AND b) + (a OR b)
End function

a. 27
b. 23
c. 25
d. 24

11. What will be the output of this Infosys assessment code for x = 8?

Integer computeSequence(Integer x) cs(8) -> cs(7)+cs(6)


if(x <= 1) cs(7) -> cs(6) + cs(5)
cs(6) -> cs(5) +cs(4)
return x cs(5)-> cs(4)+cs(3)
return computeSequence(x-1) + computeSequence(x-2) cs(4)-> cs(3) +cs(2)
cs(3)-> cs(2)+cs(1)
End function
cs(2) -> cs(1) + cs(0)
cs(1) -> return 1
cs(0) return 0
a. 21 come from down to up
b. 34
0 -> 0
c. 13 cs(1)->1 , cs(2)->1 ,
d. 55 cs(3)->2 , 4->3, cs(5)->5....etc

12. This pattern matching code appeared in an Infosys test. What's the output for n = 3?

Integer createPattern(Integer n) for i =1:


Integer result = 0 for j = 1 to i ( 1 to 1) -> j=1
res= 0+1 =1
for i = 1 to n (1 to 3)
for j = 1 to i
for i =2 :
result = result + i j = 1 to 2 -> 1 & 2
End for
for j =1 -> res = 1+2 = 3
for j = 2 > res = 3+2 = 5
End for
return result
for i=3:
End function j = 1,2,&3:
for j=1 -> res=5+3 = 8
for j=2 -> res = 8+3 =11
a. 10 for j=3 -> res = 11+3 -> 14
b. 9
c. 14
d. 12

13. An Infosys interviewer presented this recursive code. What's the output for n = 5?

Integer specialSum(Integer n) 5 + ss(3)


if(n <= 0)
return 0 3+ ss(1)
return n + specialSum(n-2)
1+ ss(-1)
End function

a. 9
b. 15
c. 6
d. 12

14. This bit manipulation question appeared in an Infosys test. What's returned for x = 36?

Integer findRightmostBit(Integer x) x=36->100100 pos=1+1+1


Integer position = 1 x=18 -> 10010
x=9 -> 1001
while(x > 0)
if(x mod 2 EQUALS 1)
return position
position = position + 1
x = x/2
End while
return 0
End function

a. 3
b. 2
c. 4
d. 5

15. During an Infosys coding round, this array processing code was given. What's the output for arr = [2,4,6,8,10]?

Integer processArray(Array arr)


Integer result = 0
for i = 0 to length(arr)-1
if(arr[i] mod 4 EQUALS 0)
result = result + 1
End for
return result
End function

a. 2
b. 3
c. 1
d. 4

16. What will be the output of this string manipulation code from an Infosys assessment for str = "PROGRAM"?
Integer analyzePattern(String str)
Integer count = 0
for i = 0 to length(str)-1
if str[i] EQUALS str[length(str)-1-i]
count = count + 1
End for
return count
End function

a. 1
b. 2
c. 3
d. 4

17. This mathematical sequence appeared in an Infosys test. What's the output for n = 6?

Integer generateSequence(Integer n)
if(n <= 2)
return 1
return generateSequence(n-1) + generateSequence(n-3)
End function

a. 5
b. 4
c. 6
d. 7

18. An Infosys interviewer asked about this array transformation code. What's returned for arr = [1,3,5,7,9]?

Integer transformArray(Array arr)


Integer sum = 0
for i = 1 to length(arr)-2 i takes 3 values or 3 iterations
sum = sum + arr[i]
End for
return sum
End function

a. 15
b. 25
c. 8
d. 12

19. What will be the output of this logical operation code from an Infosys test for a = 6, b = 9?
0110 -> 6
1001 ->9

Integer logicalCompute(Integer a, Integer b)


return (a XOR b) + (NOT(a AND b))
End function

a. 15 15+15->30 or
1111 -> 15 (a^b) a&b -> 0000 -> 0 -> not(0) -> 1
b. 13 15+1=16
c. 14 or
a&b -> 0000 -> not(0000) -> 1111 ->15
d. 16

20. During an Infosys assessment, this pattern recognition code was given. What's the output for n = 4?

Integer recognizePattern(Integer n)
i=1 -> res = 0+1 =1
Integer result = 0 i=2 -> res = 1+2 =3
for i = 1 to n
i=3 -> skip
i=4 -> res =3+4 =7
if(n mod i EQUALS 0)
result = result + i
End for
return result
End function

a. 7
b. 8
c. 9
d. 10

21. This recursive pattern appeared in an Infosys coding test. What's returned for n = 5?

Integer computePattern(Integer n) 5-> cp(4) -> 7


4-> 4+cp(2) -> 7
if(n <= 1) 2-> 2+cp(0) ->3
return 1 0->1
if(n mod 2 EQUALS 0)
return n + computePattern(n-2)
return computePattern(n-1)
End function

a. 6
b. 8
c. 10
d. 12

22. An Infosys interviewer presented this string counting code. What's the output for str = "INFOSYS2024"?
Integer countSpecial(String str)
Integer count = 0
for each char in str
if char is digit OR char in ['A','E','I','O','U']
count = count + 1
End for
return count
End function

a. 5
b. 6
c. 7
d. 8

23. What will be the output of this array processing code from an Infosys test for arr = [2,3,4,5,6]?

Integer processElements(Array arr)


Integer product = 1
for i = 0 to length(arr)-1
if(arr[i] mod 2 EQUALS 0)
product = product * arr[i]
End for
return product
End function

a. 48
b. 24
c. 36
d. 12

24. During an Infosys coding round, this mathematical sequence was given. What's returned for n = 7?

Integer sequenceSum(Integer n) 7 -> 49 + ss(5) -> 84


5-> 25 + ss(3) -> 35
if(n <= 0) 3-> 9+ss(1) -> 10
return 0 1->1+ss(-1) ->1
ss(-1) ->0
return n*n + sequenceSum(n-2)
End function

a. 84
b. 77
c. 91
d. 105

25. This bit counting code appeared in an Infosys assessment. What's the output for n = 15?
Integer countSetBits(Integer n) 15 -> 1111 c=1
Integer count = 0 14-> 1110 -> 1110
while(n > 0)
1110
n = n AND (n-1) 1101
count = count + 1
End while
return count
End function

a. 3
b. 4
c. 5
d. 6

26. An Infosys interviewer asked about this array manipulation code. What's returned for arr = [1,2,3,2,1]?

Boolean checkArray(Array arr)


for i = 0 to length(arr)/2
if arr[i] NOT EQUALS arr[length(arr)-1-i]
return false
End for
return true
End function

a. true
b. false
c. 1
d. 0

27. What will be the output of this pattern generation code from an Infosys test for n = 3?

Integer generateValue(Integer n) i=1 , j =1,2,3 -> j=1-> res = 0+1= 1


j=2 -> res = 1+2 = 3
Integer result = 0
j=3 -> res = 3+ 3 = 6
for i = 1 to n i=2,j=2,3 -> j=2 -> res = 6+4 =10
for j = i to n j=3 -> res = 10+6 =16
i=3 , j=3 -> res = 16+9 -> 25
result = result + i*j
End for
End for
return result
End function

a. 23
b. 25
c. 27
d. 29

28. During an Infosys assessment, this string manipulation code was given. What's the output for str = "TESTING"?

String transformString(String str)


String result = ""
for i = 0 to length(str)-1
if i mod 2 EQUALS 0
result = result + str[i]
End for
return result
End function

a. "TEST"
b. "TSIG"
c. "TING"
d. "ESTN"

29. This mathematical computation appeared in an Infosys coding test. What's returned for a = 4, b = 3?

Integer computeValue(Integer a, Integer b) res = 4


Integer result = 1
while(b > 0)
a=16 , b=1 -> res = 4*16 -> 64
if(b mod 2 EQUALS 1)
result = result * a
a = a * a
b = b/2
End while
return result
End function

a. 64
b. 81
c. 16
d. 32

30. An Infosys interviewer presented this array processing code. What's the output for arr = [4,2,7,1,9]?
Integer analyzeArray(Array arr)
Integer max_diff = 0
4-2 = 2>0 so max_diff =2
for i = 0 to length(arr)-2
abs(2-7) =5>2 sp max_diff =5
if abs(arr[i] - arr[i+1]) > max_diff
max_diff = abs(arr[i] - arr[i+1])
End for
return max_diff
End function

a. 5
b. 6
c. 7
d. 8

You might also like