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

Practice - Question - Coding

The document outlines a series of programming tasks, including generating FizzBuzz, checking for palindromes, generating Fibonacci sequences, calculating factorials, implementing binary search, counting character occurrences, merging sorted arrays, removing duplicates, and calculating specific sums and carries. Each task includes a brief description and, in some cases, example inputs and outputs. The tasks are designed to test various programming skills and algorithmic thinking.

Uploaded by

rajeshnaidu51844
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Practice - Question - Coding

The document outlines a series of programming tasks, including generating FizzBuzz, checking for palindromes, generating Fibonacci sequences, calculating factorials, implementing binary search, counting character occurrences, merging sorted arrays, removing duplicates, and calculating specific sums and carries. Each task includes a brief description and, in some cases, example inputs and outputs. The tasks are designed to test various programming skills and algorithmic thinking.

Uploaded by

rajeshnaidu51844
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Question 1:

Write a program that prints the numbers from 1 to 100. But for multiples of three,
print “Fizz” instead of the number, and for the multiples of five, print “Buzz”. For
numbers that are multiples of both three and five, print “FizzBuzz”.

Question 2:
Write a function to determine if a given string is a palindrome.

Question 3:
Write a function to generate the Fibonacci sequence up to a specified number of
terms.

Question 4:
Write a function to calculate the factorial of a given number.

Question 5:
Implement the binary search algorithm to find the index of a given element in a
sorted array.

Question 6:
Write a function to count the occurrences of each character in a given string.

Question 7:
Write a function to merge two sorted arrays into a single sorted array.
[1,4,8,10,16,25], [2,6,8,11,22]

Question 8:
Write a function to remove duplicates from a sorted array in-place such that each
unique element appears only once and returns the new length.
[0,1,45,1,12,4,12,1,23,1]
Question 9:
productSmallestPair(sum, arr)
The function accepts an integers sum and an integer array arr of size n. Implement
the function to find the pair, (arr[j], arr[k]) where j!=k, Such that arr[j] and arr[k] are
the least two elements of array (arr[j] + arr[k] <= sum) and return the product of
element of this pair
NOTE

● Return -1 if array is empty or if n<2


● Return 0, if no such pairs found
● All computed values lie within integer range

Input
Sum: 9
size of Arr: 7
Arr: 5 2 4 3 9 7 1
Output
2

Question 10:
largeSmallSum(arr)
The function accepts an integers arr of size ’length’ as its arguments you are
required to return the sum of second largest element from the even positions and
second smallest from the odd position of given ‘arr’
Assumption:
● All array elements are unique
● Treat the 0th position as even
NOTE
● Return 0 if array is empty
● Return 0, if array length is 3 or less than 3
Input
Arr: 3 2 1 7 5 4
Output
7

Question 11:
moveHyphen(str, length)
The function accepts a string “str” of length ‘n’, that contains alphabets and
hyphens (-). Implement the function to move all hyphens(-) in the string to the
front of the given string.
NOTE:- Return null if str is null.
Example :-
● Input:
○ str.Move-Hyphens-to-Front
● Output:
○ —MoveHyphenstoFront

Question 12:
numberOfCarries(int num1 , int num2)
A carry is a digit that is transferred to left if sum of digits exceeds 9 while adding
two numbers from right-to-left one digit at a time. The functions accepts two
numbers ‘num1’ and ‘num2’ as its arguments. You are required to calculate and
return the total number of carries generated while adding digits of two numbers
‘num1’ and ‘ num2’.
Assumption: num1, num2>=0
Example:
● Input
○ Num 1: 451
○ Num 2: 349
● Output
○ 2
Explanation: Adding ‘num 1’ and ‘num 2’ right-to-left results in 2 carries since ( 1+9)
is 10. 1 is carried and (5+4) is 9, again 1 is carried. Hence 2 is returned.
Sample Input
Num 1: 23
Num 2: 563
Sample Output
0

You might also like